80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Prizes;
|
|
|
|
use App\Models\Prize;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class StorePrizeRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return Gate::check('create', Prize::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'pdf_winning_proof' => $this->input('pdf_winning_proof')
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
$rules = [
|
|
'label' => 'required|string|min:3|max:255',
|
|
'picture_alt' => 'required|string|between:3,255',
|
|
'picture_title' => 'required|string|between:3,255',
|
|
'arg_title' => 'required|string|min:3|max:255',
|
|
'arg_subtitle' => 'nullable|string|min:3|max:255',
|
|
'arg_content' => 'required|string|min:15',
|
|
'quantity' => 'required|numeric|min:1',
|
|
'pdf_winning_proof' => 'nullable|file|mimes:pdf',
|
|
];
|
|
$width = config('theme.models.prizes.picture_max_width');
|
|
$height = config('theme.models.prizes.picture_max_height');
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('picture', $width, $height, $width, $height),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'label' => trans('validation.custom.label'),
|
|
'picture' => trans('validation.custom.picture'),
|
|
'picture_alt' => trans('validation.custom.picture_alt'),
|
|
'picture_title' => trans('validation.custom.picture_title'),
|
|
'arg_title' => trans('validation.attributes.title'),
|
|
'arg_subtitle' => trans('validation.custom.subtitle'),
|
|
'arg_content' => trans('validation.attributes.content'),
|
|
'quantity' => trans('validation.custom.quantity'),
|
|
'pdf_winning_proof' => trans('validation.custom.pdf_winning_proof'),
|
|
];
|
|
}
|
|
}
|