Files
AWA/laravel/app/Http/Requests/StoreCommentairesRequest.php
2025-06-10 21:17:33 +02:00

51 lines
1.4 KiB
PHP
Executable File

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\Rule;
class StoreCommentairesRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'COM_DATE' => ['required', 'date'],
'COM_CONTENU' => ['required', 'string', 'max:200'],
'billet_id' => ['required', 'integer'],
'user_id' => ['required', 'integer', Rule::exists('users', 'id')->where(function ($query) {
$query->where('id', $this->user()->id);
})],
];
}
public function failedValidation(\Illuminate\Contracts\Validation\Validator $validator) {
throw new HttpResponseException(
response()->json([
'success' => false,
'message' => 'Validation failed',
'data' => $validator->errors(),
], 422)
);
}
public function validated($key = null, $default = null)
{
return parent::validated($key, $default);
}
}