Files
ISI2/laravel/app/Http/Requests/CommentaireRequest.php
2025-06-03 14:46:58 +02:00

40 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Contracts\Validation\Validator;
class CommentaireRequest 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_AUTEUR' => ['required', 'string', 'max:100'],
'COM_CONTENU' => ['required', 'string', 'max:200'],
'billet_id' => ['required', 'integer'],
];
}
public function failedValidation(Validator $validator){
throw new HttpResponseException(response()->json([
'success' => false,
'message' => 'Validation errors',
'data' => $validator->errors()
]));
}
}