Check if the route have any query string?
I want to check if the current route have any query string on it no matter the key or value, Which method should i use in $request instance?
Laravel has a $request->has method.
It can be found in the request chapter.
that method only check one key, I'm looking for something that check if query string applied to the route (no specific key value matter)
Did you try $request->all();
@sinnbeck thanks, That' a hacky way, Do you think it worth if i apply a macro method in Request class ? It would be nice if the method returns boolean
Well the clean way is doing something like in the link by @jlrdw
Checking the content of $_SERVER['QUERY_STRING'] might work
if will be better if laravel has any method on it rather than using $_SERVER
You can access the ParameterBag that holds the query parameters from the Request, then use its count method.
use Illuminate\Http\Request;
Route::get('/', function (Request $request) {
return $request->query->count();
});
No need to complicate it by checking $_SERVER['QUERY_STRING'] or $_GET when Symfonys' ParameterBag and Laravel handle it for you. 🙂
@thinkverse only two years too late. But I agree with your way of doing it. It's how I would do it with my current knowledge :)
@Sinnbeck better late than never right. Hopefully, it might help someone who is looking to do the same thing. 🙂
Please or to participate in this conversation.