44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Ranges;
|
|
|
|
use App\Models\Breeder;
|
|
use App\Models\Recipe;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class RangeModelTitleRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth()->check() and $this->json();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'id' => 'required|numeric',
|
|
'model' => [
|
|
\sprintf('in:%s,%s', Breeder::class, Recipe::class),
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed,Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
$table = (new $value())->getTable();
|
|
Validator::validate(
|
|
['model' => $this->id],
|
|
['model' => "required|exists:{$table},id"]
|
|
);
|
|
}
|
|
]
|
|
];
|
|
}
|
|
}
|