44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Destination\app\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Modules\Destination\app\Models\Destination;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
|
|
class UpdateDestinationRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$destination = Destination::where('uuid', $this->route('uuid'))->first();
|
|
|
|
return [
|
|
'title' => 'required|string',
|
|
'country_id' => 'required|exists:countries,id',
|
|
'ordering' => 'required|integer|unique:destinations,ordering,' . ($destination ? $destination->id : 'NULL') . ',id',
|
|
'activities' => 'required',
|
|
'rating' => 'required|integer|between:1,5',
|
|
'image' => 'sometimes|nullable',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
protected function failedValidation(Validator $validator)
|
|
{
|
|
$message = $validator->errors()->first();
|
|
toastr()->error($message);
|
|
parent::failedValidation($validator);
|
|
}
|
|
}
|