49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo;
|
|
|
|
use App\Enums\OCBType;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreDansLesPresContentRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
$this->merge([
|
|
'isVideo' => $this->isVideo ? true : false,
|
|
'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_if:isVideo,false|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1366,height=553',
|
|
'video_link' => 'required_if:isVideo,true|max:255',
|
|
'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'");
|
|
}
|
|
}
|
|
],
|
|
'isVideo' => 'required|boolean',
|
|
'status' => 'required|boolean'
|
|
];
|
|
}
|
|
}
|