Answer the question
In order to leave comments, you need to log in
Checking for the existence of a Request in Laravel?
Guys, help. How to use the Validator in Laravel to check for the existence of a key in an array?
$request = [];
$validator = Validator::make($request, [
'min' => 'nullable',
'max' => 'nullable',
]);
// nullable - не подходит, т.к если ключ в массиве не существует он его пропустит
// required - тоже не подходит, т.к он проверяет значение равно ли ''
if(!isset($request['min'])) return false;
if(!isset($request['max'])) return false;
Answer the question
In order to leave comments, you need to log in
With your statement of the required question, the most correct answer.
Therefore, it is worth deciding what exactly you want to check.
And then go to the documentation and select the desired rules.
https://laravel.com/docs/5.8/validation#available-...
Checking if min, max are required
$validator = Validator::make($request, [
'min' => 'required',
'max' => 'required',
]);
$validator = Validator::make($request, [
'min' => 'required|integer',
'max' => 'required|integer',
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question