81 lines
2.6 KiB
PHP
81 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Back\Companies;
|
|
|
|
use App\Models\Company;
|
|
use App\Traits\Requests\HasInertiaPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Uwil\LaravelCommon\Rules\WysiwygLength;
|
|
|
|
class StoreCompanyRequest extends FormRequest
|
|
{
|
|
use HasInertiaPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', Company::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'published' => $this->boolean('published'),
|
|
]);
|
|
$this->mergeInertiaPicture();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => 'required|string|between:3,255|unique:companies,name',
|
|
'logo' => $this->pictureRules(
|
|
'required|nullable|file|mimes:jpg,jpeg,png,webp|max:5120|dimensions:width=500,height=500',
|
|
),
|
|
'responsable' => 'required|nullable|string|between:3,255',
|
|
'url' => 'nullable|string|between:3,255',
|
|
'informations' => ['required', 'string', new WysiwygLength(10, 5000)],
|
|
'employees' => 'required|nullable|numeric|between:0,100000',
|
|
'latitude' => 'required|numeric|between:-90,90',
|
|
'longitude' => 'required|numeric|between:-180,180',
|
|
'activity_id' => 'required|numeric|exists:company_activities,id',
|
|
'sector_id' => 'required|nullable|numeric|exists:company_sectors,id',
|
|
'published' => 'required|boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => trans('validation.attributes.name'),
|
|
'logo' => trans('validation.custom.logo'),
|
|
'informations' => trans('validation.custom.informations'),
|
|
'responsable' => trans('validation.custom.responsable'),
|
|
'latitude' => trans('validation.custom.latitude'),
|
|
'longitude' => trans('validation.custom.longitude'),
|
|
'activity_id' => trans('models.classes.activity'),
|
|
'sector_id' => trans('models.classes.sector'),
|
|
'published' => trans('validation.custom.published'),
|
|
];
|
|
}
|
|
}
|