0

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.

1 Answer 1

1

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!
}
Sign up to request clarification or add additional context in comments.

2 Comments

In my situation is : $validated->has('q') ?
No, in your situation its request()->has('q').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.