70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Professions;
|
|
|
|
use App\Models\Profession;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class StoreProfessionRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', Profession::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'published' => $this->boolean('published'),
|
|
]);
|
|
$this->mergePicture('picture');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'title' => 'required|string|between:3,255',
|
|
'picture_alt' => 'required_with:picture|nullable|between:3,255',
|
|
'picture_title' => 'required_with:picture|nullable|between:3,255',
|
|
'jobs_list.*' => 'required|array',
|
|
'jobs_list.*.value' => 'required|string|between:3,255',
|
|
'job_url' => 'required|string|between:3,255|url:http,https',
|
|
'published' => 'required|boolean',
|
|
];
|
|
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('picture', 300, 200, 300, 200),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'title' => trans('validation.attributes.title'),
|
|
'picture' => trans('validation.attributes.image'),
|
|
'picture_alt' => trans('validation.custom.attribute_alt'),
|
|
'picture_title' => trans('validation.custom.attribute_title'),
|
|
'jobs_list' => trans('validation.custom.jobs_list'),
|
|
'jobs_list.*.value' => trans('validation.custom.jobs_list'),
|
|
'job_url' => trans('validation.attributes.job_url'),
|
|
'published' => trans('validation.attributes.published'),
|
|
];
|
|
}
|
|
}
|