finished api
This commit is contained in:
50
laravel/app/Http/Requests/StoreCommentairesRequest.php
Normal file
50
laravel/app/Http/Requests/StoreCommentairesRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user