Selam, request sınıfı tanımlarken bir request sınıfı kullanarak diger request sınıfında kullanabilirsiniz. Örneğin:
StorePostRequest.php
class StorePostRequest 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 [
'body' => ['nullable', 'string'],
'attachments.*' => 'array|max:50',
'attachments.*' => [
'file',
File::types(['jpg', 'jpeg', 'png', 'gif', 'webp', 'mp3', 'wav', 'mp4', 'doc', 'docx', 'pdf', 'csv', 'xls', 'xlsx', 'zip'])
->max(500 * 1024 * 1024)
],
'user_id' => ['numeric']
];
}
UpdatePostRequest.php
class UpdatePostRequest extends StorePostRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
$post = $this->route('post');
return $post->user_id == auth()->id();
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return array_merge(parent::rules(), [
'deleted_file_ids' => 'array',
'deleted_file_ids.*' => 'numeric'
]);
}
}
UpdatePostRequest
'de StorePostRequest
'ı kullanarak StorePostRequest
'de olan kuralları UpdatePostRequest
kullanabiliyorsunuz/
Ve
public function rules(): array
{
return array_merge(parent::rules(), [
'deleted_file_ids' => 'array',
'deleted_file_ids.*' => 'numeric'
]);
}
yaparakta birleştiriyoruz.