57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Bo\Folders;
|
||
|
|
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
|
||
|
|
class StoreFolderRequest extends FormRequest
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Determine if the user is authorized to make this request.
|
||
|
|
*
|
||
|
|
* @return boolean
|
||
|
|
*/
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return auth()->check();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Prepare the data for validation.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
protected function prepareForValidation()
|
||
|
|
{
|
||
|
|
$this->merge([
|
||
|
|
'sub' => $this->sub ? true : false,
|
||
|
|
'is_private' => $this->status ? true : false,
|
||
|
|
'marques' => !$this->marques ? null : \explode(',', \strval($this->marques))
|
||
|
|
]);
|
||
|
|
if ($this->sub) {
|
||
|
|
$this->merge([
|
||
|
|
'is_private' => false
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the validation rules that apply to the request.
|
||
|
|
*
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function rules()
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'parent_id' => 'sometimes|exists:dossiers,id',
|
||
|
|
'libelle' => 'required|string|min:4|max:255|unique:dossiers,libelle',
|
||
|
|
'description' => 'nullable|string|min:4',
|
||
|
|
'sujet' => 'required_unless:sub,true|exists:sujets,codeSujet',
|
||
|
|
'is_private' => 'required|boolean',
|
||
|
|
'marques' => 'nullable|array',
|
||
|
|
'marques.*' => 'required|exists:marques,codMarq',
|
||
|
|
'sub' => 'required|boolean'
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|