ldc-legaulois/app/Http/Requests/Bo/Offers/StoreOfferRequest.php
2024-07-15 10:25:41 +02:00

80 lines
2.4 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Offers;
use App\Models\Offer;
use App\Rules\WysiwygLength;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
class StoreOfferRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Gate::check('create', Offer::class);
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
{
$this->merge([
'published' => $this->boolean('published')
]);
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [
'title' => 'required|string|between:3,255',
'location' => 'required|string|between:3,255',
'contract' => 'required|string|between:3,255',
'function' => 'required|string|between:3,255',
'picture_alt' => 'required_with:picture|nullable|between:3,255',
'picture_title' => 'required_with:picture|nullable|between:3,255',
'description' => ['required', 'string', new WysiwygLength()],
'published' => 'required|boolean',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 300, 200, 300, 200, true),
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'title' => trans('validation.attributes.title'),
'location' => trans('validation.custom.location'),
'contract' => trans('validation.custom.contract'),
'function' => trans('validation.custom.function'),
'picture' => trans('validation.attributes.image'),
'picture_alt' => trans('validation.custom.attribute_alt'),
'picture_title' => trans('validation.custom.attribute_title'),
'description' => trans('validation.attributes.description'),
'published' => trans('validation.attributes.published')
];
}
}