79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Documents;
|
|
|
|
use App\Enums\Documents\LangEnum;
|
|
use App\Models\Document;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
class StoreDocumentRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'status' => $this->status ? true : false
|
|
]);
|
|
if (Document::query()->where('id', $this->document_id)->exists()) {
|
|
$this->merge([
|
|
'directory_id' => Document::query()->where('id', $this->document_id)
|
|
->value('directory_id')
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'directory_id' => 'required|integer',
|
|
'document_id' => 'sometimes:directory_id|nullable|integer',
|
|
'title' => 'required|min:3|max:255',
|
|
'type' => 'required|min:3|max:255',
|
|
'path' => 'required|min:3|max:255',
|
|
'lang' => [
|
|
'required',
|
|
new EnumIsValidRule(LangEnum::class)
|
|
],
|
|
'status' => 'required|boolean'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes()
|
|
{
|
|
return [
|
|
'directory_id' => \trans('dossier à associer'),
|
|
'document_id' => \trans('document (FR) à associer'),
|
|
'title' => \trans('titre'),
|
|
'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'),
|
|
];
|
|
}
|
|
}
|