---
name: project-conventions
description: Core coding conventions for the Mediknode/Unified Laravel 11 + Livewire 3 event-management codebase. Use whenever writing or editing PHP controllers, models, services, routes, or Blade views in this project, to match existing style (French locale, service layer, responses, validation, RBAC).
---

# Mediknode / Unified — coding conventions

Apply these whenever you touch project code. When the code and CLAUDE.md disagree, **follow the code** and note the drift.

## Responses & control flow
- Reads: `return view('backend.foo.index', compact('bar'));`
- Mutations: redirect with a French flash message — `return redirect()->route('foo.index')->with('success', 'Participant validé.');`
- Use `findOrFail` / `firstOrFail`, never silent nulls.

## Validation
- Newer controllers use **Form Request** classes in `app/Http/Requests/` (e.g. `ParticipantCreateRequest`). Prefer them for non-trivial input.
- Inline `$request->validate([...])` is fine for 1–2 fields. (CLAUDE.md says inline-only; the code now uses both — follow the code.)
- Validation messages in **French**.

## Services
- Business logic lives in `app/Services/` singletons (registered in `AppServiceProvider`): `ParticipantRegistrationService`, `PaymentService`, `PDFGenerationService`, `WorkshopPricingService`, `UserService`, `HebergementPaymentService`, etc.
- Inject via constructor. Keep controllers thin.

## Models & relationships
- All models in `app/Models/`, all use `HasFactory`.
- Define **both sides** of every relationship.
- `SoftDeletes` is currently on only 5 models (`User`, `Participant`, `Show`, `Doctor`, `Lista`) — not universal. Check before assuming `withTrashed()` works.
- InnoDB + utf8mb4 forced globally.

## Locale
- French everywhere user-facing: strings, dates (`Carbon::setLocale('fr')`), flash messages, validation, even test method names.

## RBAC
- Spatie `laravel-permission`. Gate backend actions with `permission:`/`role:` middleware or `$user->can()`. Reuse existing permission names — grep before inventing one.

## Code style
- Run `vendor/bin/pint` on every file you touch before finishing.
- `php -l <file>` to sanity-check syntax when editing standalone scripts/routes.

See also: [[routing-multisubdomain]], [[meta-pattern]], [[audit-observers]], [[testing-conventions]].
