feat: add form request validation classes
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AirportStoreRequest 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, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:150'
|
||||
],
|
||||
'city' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:100'
|
||||
],
|
||||
'country' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:100'
|
||||
],
|
||||
'code' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:10'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// public function messages(): array
|
||||
// {
|
||||
// return [
|
||||
// 'name.required' => 'نام فرودگاه الزامی است.',
|
||||
// 'name.max' => 'نام فرودگاه حداکثر ۱۵۰ کاراکتر باشد.',
|
||||
// 'city.required' => 'نام شهر الزامی است.',
|
||||
// 'city.max' => 'نام شهر حداکثر ۱۰۰ کاراکتر باشد.',
|
||||
// 'country.required' => 'نام کشور الزامی است.',
|
||||
// 'country.max' => 'نام کشور حداکثر ۱۰۰ کاراکتر باشد.',
|
||||
// 'code.required' => 'کد فرودگاه (IATA) الزامی است.',
|
||||
// 'code.max' => 'کد فرودگاه حداکثر ۱۰ کاراکتر باشد.',
|
||||
// ];
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CommentUpdateRequest 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, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'body' =>
|
||||
[
|
||||
'required',
|
||||
'string'
|
||||
],
|
||||
'status' =>
|
||||
[
|
||||
'required',
|
||||
'integer',
|
||||
Rule::in([0, 1, 2])
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class FavoriteUpdateRequest 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, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' =>
|
||||
[
|
||||
'required', 'integer', 'exists:users,id'
|
||||
],
|
||||
'favoritable_id' =>
|
||||
[
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'favoritable_type' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:100'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class SettingUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* آمادهسازی دادهها بر اساس ردیفهای موجود در جدول.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$allowedCodes = Setting::pluck('code')->all();
|
||||
|
||||
// فقط codeهایی که در جدول وجود دارند را نگاه میداریم
|
||||
$filtered = Arr::only($this->all(), $allowedCodes);
|
||||
|
||||
$this->merge($filtered);
|
||||
}
|
||||
|
||||
/**
|
||||
* قوانین اعتبارسنجی.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$codes = Setting::pluck('code')->all();
|
||||
|
||||
return collect($codes)
|
||||
->mapWithKeys(fn($code) => [
|
||||
$code => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:65535'
|
||||
],
|
||||
])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TourStoreRequest 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, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'travel_type_id' =>
|
||||
[
|
||||
'required',
|
||||
'exists:travel_types,id'
|
||||
],
|
||||
'title' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:200'
|
||||
],
|
||||
'slug' =>
|
||||
['required', 'string',
|
||||
'max:200',
|
||||
'regex:/^[a-z0-9-]+$/',
|
||||
'unique:tours,slug,' . $this->tour
|
||||
],
|
||||
|
||||
'description' =>
|
||||
[
|
||||
'required',
|
||||
'string'
|
||||
],
|
||||
'duration' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:50'
|
||||
],
|
||||
'start_date' =>
|
||||
[
|
||||
'required',
|
||||
'date'
|
||||
],
|
||||
'end_date' =>
|
||||
[
|
||||
'required',
|
||||
'date',
|
||||
'after_or_equal:start_date'
|
||||
],
|
||||
'price' =>
|
||||
[
|
||||
'required',
|
||||
'numeric',
|
||||
'min:0'
|
||||
],
|
||||
'capacity' =>
|
||||
[
|
||||
'required',
|
||||
'integer',
|
||||
'min:0'],
|
||||
'status' =>
|
||||
[
|
||||
'nullable',
|
||||
'in:0,1'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class UserStoreRequest 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, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
|
||||
'email' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'email',
|
||||
'max:255',
|
||||
'unique:users,email'
|
||||
],
|
||||
'password' =>
|
||||
[
|
||||
'required',
|
||||
'confirmed',
|
||||
Password::defaults()
|
||||
],
|
||||
];
|
||||
}
|
||||
// public function messages(): array
|
||||
// {
|
||||
// return [
|
||||
// 'name.required' => 'نام و نام خانوادگی الزامی است.',
|
||||
// 'email.required' => 'ایمیل الزامی است.',
|
||||
// 'email.email' => 'فرمت ایمیل معتبر نیست.',
|
||||
// 'email.unique' => 'این ایمیل قبلاً ثبت شده است.',
|
||||
// 'password.required' => 'رمز عبور الزامی است.',
|
||||
// 'password.confirmed' => 'تکرار رمز عبور مطابقت ندارد.',
|
||||
// ];
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user