63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Enums\RecipeFilter;
|
|
use App\Exceptions\RedirectTo;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class RecipeIndexRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
if ($this->type) {
|
|
$this->merge([
|
|
'type' => $this->type
|
|
]);
|
|
}
|
|
if ($this->value) {
|
|
$this->merge([
|
|
'value' => $this->value
|
|
]);
|
|
}
|
|
if ($this->search) {
|
|
$this->merge([
|
|
'search' => $this->search
|
|
]);
|
|
}
|
|
if ($this->video_recipe) {
|
|
$this->merge([
|
|
'video_recipe' => $this->video_recipe
|
|
]);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'type' => [
|
|
'sometimes',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed,Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if (!in_array($value, RecipeFilter::toValues())) {
|
|
throw new RedirectTo(route('recipes.index'));
|
|
}
|
|
}
|
|
],
|
|
'value' => 'sometimes',
|
|
'search' => 'sometimes',
|
|
'video_recipe' => 'sometimes'
|
|
];
|
|
}
|
|
}
|