2025-12-01 15:55:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-12 17:14:08 +01:00
|
|
|
namespace App\Http\Requests\Back\Documents;
|
2025-12-01 15:55:32 +01:00
|
|
|
|
2025-12-09 11:29:10 +01:00
|
|
|
use App\Enums\Document\DocumentStatusEnum;
|
|
|
|
|
use App\Enums\YearsEnum;
|
|
|
|
|
use App\Models\Document;
|
2025-12-01 15:55:32 +01:00
|
|
|
use App\Traits\Requests\HasInertiaPicture;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
|
|
2025-12-09 11:29:10 +01:00
|
|
|
class StoreDocumentRequest extends FormRequest
|
2025-12-01 15:55:32 +01:00
|
|
|
{
|
|
|
|
|
use HasInertiaPicture;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
2026-02-10 15:43:47 +01:00
|
|
|
*
|
|
|
|
|
* @return boolean
|
2025-12-01 15:55:32 +01:00
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
2025-12-09 11:29:10 +01:00
|
|
|
return Gate::check('create', Document::class);
|
2025-12-01 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->mergeInertiaPicture();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-01-29 17:01:20 +01:00
|
|
|
'name' => 'required|string|between:3,255',
|
|
|
|
|
'exercice' => ['nullable', new Enum(YearsEnum::class)],
|
|
|
|
|
'status' => ['required', new Enum(DocumentStatusEnum::class)],
|
|
|
|
|
'published_at' => 'nullable|date',
|
|
|
|
|
'unpublished_at' => 'nullable|date|after:published_at',
|
|
|
|
|
'path' => $this->pictureRules('nullable|file|mimes:pdf|max:10240'),
|
|
|
|
|
'issuu_path' => 'nullable|string|between:3,1000',
|
|
|
|
|
'is_issuu' => 'required|boolean',
|
|
|
|
|
'tags' => 'nullable|array',
|
|
|
|
|
'tags.*' => 'integer|exists:document_tags,id',
|
|
|
|
|
'categories' => 'nullable|array',
|
|
|
|
|
'categories.*' => 'integer|exists:document_categories,id',
|
2025-12-01 15:55:32 +01:00
|
|
|
];
|
|
|
|
|
}
|
2026-01-09 17:03:30 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'issuu_path' => trans('validation.custom.issuu_path'),
|
|
|
|
|
'is_issuu' => trans('validation.custom.is_issuu'),
|
|
|
|
|
];
|
|
|
|
|
}
|
2025-12-01 15:55:32 +01:00
|
|
|
}
|