ldc-groupe/app/Http/Requests/Back/Companies/StoreCompanyRequest.php

82 lines
2.6 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Requests\Back\Companies;
use App\Models\Company;
use App\Traits\Requests\HasInertiaPicture;
2026-02-12 16:14:11 +01:00
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
2026-02-12 16:14:11 +01:00
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 [
2026-02-12 16:14:11 +01:00
'name' => 'required|string|between:3,255|unique:companies,name',
2026-02-10 15:43:47 +01:00
'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',
2026-02-12 16:14:11 +01:00
'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'),
];
}
}