2024-04-12 12:15:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Approaches;
|
|
|
|
|
|
|
|
|
|
use App\Models\Approach;
|
|
|
|
|
use App\Traits\Requests\HasPicture;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
|
|
class StoreApproachRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
use HasPicture;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return Gate::check('create', Approach::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'type' => intval($this->route()->parameter('approach_type')),
|
|
|
|
|
'published' => $this->boolean('published')
|
|
|
|
|
]);
|
|
|
|
|
$this->mergePicture('picture');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
$rules = [
|
|
|
|
|
'type' => 'required|numeric|between:0,1',
|
|
|
|
|
'name' => 'required|string|between:3,255',
|
|
|
|
|
'picture_alt' => 'required_with:picture|nullable|between:3,255',
|
|
|
|
|
'picture_title' => 'required_with:picture|nullable|between:3,255',
|
|
|
|
|
'published' => 'required|boolean',
|
|
|
|
|
];
|
|
|
|
|
return \array_merge(
|
|
|
|
|
$rules,
|
|
|
|
|
$this->pictureRules('picture', 150, 150, 150, 150),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'name' => trans('validation.attributes.name'),
|
|
|
|
|
'picture' => trans('validation.attributes.image'),
|
2024-04-19 10:08:36 +02:00
|
|
|
'picture_alt' => trans('validation.custom.attribute_alt'),
|
|
|
|
|
'picture_title' => trans('validation.custom.attribute_title'),
|
2024-04-12 12:15:18 +02:00
|
|
|
'published' => trans('validation.attributes.published')
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|