-
app/Policies/ReservationPolicy.php
Open in GitHubuse App\Models\Reservation; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; class ReservationPolicy { use HandlesAuthorization; public function view(User $user, Reservation $reservation): bool { return (int)$user->id === (int)$reservation->user_id; } public function update(User $user, Reservation $reservation): bool { return (int)$user->id === (int)$reservation->user_id; } public function delete(User $user, Reservation $reservation): bool { return (int)$user->id === (int)$reservation->user_id; } public function pay(User $user, Reservation $reservation): bool { return (int)$user->id === (int)$reservation->user_id && empty($reservation->paid_at); } }
-
app/Http/Requests/CalculatePaymentRequest.php
Open in GitHubuse App\Models\Reservation; use Illuminate\Foundation\Http\FormRequest; class CalculatePaymentRequest extends FormRequest { public function authorize(): bool { return $this->user()->can('view', Reservation::find($this->get('reservation_id'))); } public function rules(): array { return [ 'reservation_id' => ['required'] ]; } }