ldc-supportweb/app/Http/Requests/Credit/AddCreditToAccountRequest.php

42 lines
1 KiB
PHP
Raw Permalink Normal View History

2022-05-31 14:06:07 +02:00
<?php
namespace App\Http\Requests\Credit;
use Illuminate\Foundation\Http\FormRequest;
class AddCreditToAccountRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
if (!auth()->check()) {
return false;
}
/** @var \App\Models\User */
$user = auth()->user();
return $user->isAdmin() and $user->can('credit', $this->account);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'amount' => [
'required', 'numeric', 'gt:0', function ($attribute, $value, $fail) {
if ((\floatval($value) * 10) % 5 !== 0) {
$fail("$attribute doit être un multiple de 5 (comptez par demi journées, soit 0.5)");
}
}
],
];
}
}