ldc-com-app-bo/app/Http/Requests/Bo/Documents/StoreDocumentRequest.php

80 lines
2.1 KiB
PHP
Raw Normal View History

2023-03-31 17:38:44 +02:00
<?php
2023-04-05 17:20:30 +02:00
namespace App\Http\Requests\Bo\Documents;
2023-03-31 17:38:44 +02:00
2023-04-05 17:20:30 +02:00
use App\Enums\Documents\LangEnum;
2023-10-03 15:44:44 +02:00
use App\Models\Document;
2023-03-31 17:38:44 +02:00
use Illuminate\Foundation\Http\FormRequest;
2023-04-05 17:20:30 +02:00
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
2023-03-31 17:38:44 +02:00
class StoreDocumentRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
return auth('backend')->check();
}
2023-07-13 08:34:54 +00:00
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->merge([
'status' => $this->status ? true : false
]);
2023-10-03 15:44:44 +02:00
if (Document::query()->where('id', $this->document_id)->exists()) {
$this->merge([
'directory_id' => Document::query()->where('id', $this->document_id)
->value('directory_id')
]);
}
2023-07-13 08:34:54 +00:00
}
2023-03-31 17:38:44 +02:00
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
2023-10-03 15:44:44 +02:00
'directory_id' => 'required|integer',
'document_id' => 'sometimes:directory_id|nullable|integer',
2023-03-31 17:38:44 +02:00
'title' => 'required|min:3|max:255',
2023-04-05 17:20:30 +02:00
'type' => 'required|min:3|max:255',
'path' => 'required|min:3|max:255',
'lang' => [
'required',
new EnumIsValidRule(LangEnum::class)
],
2023-07-13 08:34:54 +00:00
'status' => 'required|boolean'
2023-03-31 17:38:44 +02:00
];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes()
{
return [
2023-07-13 08:34:54 +00:00
'directory_id' => \trans('dossier à associer'),
'document_id' => \trans('document (FR) à associer'),
2023-03-31 17:38:44 +02:00
'title' => \trans('titre'),
2023-07-13 08:34:54 +00:00
'uuid' => \trans('document'),
'type' => \trans('type du document'),
'path' => \trans('chemin du document'),
'lang' => \trans('langue du document'),
'status' => \trans('état de publication du document'),
2023-03-31 17:38:44 +02:00
];
}
}