ldc-legaulois/app/Http/Requests/Bo/Offers/StoreOfferRequest.php

74 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2024-07-12 12:51:54 +02:00
<?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.
*/
public function authorize(): bool
{
return Gate::check('create', Offer::class);
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
2026-09-25 16:25:31 +02:00
'published' => $this->boolean('published'),
2024-07-12 12:51:54 +02:00
]);
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*/
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',
];
2026-09-25 16:25:31 +02:00
2024-07-12 12:51:54 +02:00
return \array_merge(
$rules,
$this->pictureRules('picture', 300, 200, 300, 200, true),
);
}
/**
* Get custom attributes for validator errors.
*/
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'),
2026-09-25 16:25:31 +02:00
'published' => trans('validation.attributes.published'),
2024-07-12 12:51:54 +02:00
];
}
}