Here my code :
$validated = request()->validate([ 'q' => 'required|string', ]);
I want the same without using an array. I tried this :
$validated = request()->validate('q', 'required|string');
Thank’s for your help.
Advertisement
Answer
You can use $request->has()
to check if a parameter has been sent.
$request->has('q');
Request parameters are all strings by default, but you can do an extra check for null
by using get with a default value.
if ($request->get('q', null) !== null) { // $q is set! }