ldc-legaulois/app/Http/Requests/Bo/StoreOcbContentRequest.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2022-03-03 10:06:39 +01:00
<?php
namespace App\Http\Requests\Bo;
use App\Enums\OCBType;
use Illuminate\Foundation\Http\FormRequest;
class StoreOcbContentRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
$this->merge([
'status' => $this->status ? true : false
]);
return auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1366,height=553',
'content' => 'required|string|min:10',
'type' => [
'required',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
$types = OCBType::toValues();
if (!\in_array(\intval($value), $types)) {
$fail("Le type n'est pas valide '$value'");
}
}
],
'status' => 'required|boolean'
];
}
}