Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

p0t4t0's avatar

Need clarification on query strings with Laravel

How should one handle query strings with Laravel? Is this fine? If it is then are there better or more ways to do it? What instances is it better to use it over "pretty" URLs?

Route::post('/comment?pid={post}', 'CommentController@store');
0 likes
5 replies
morteza's avatar

You can do this:

Route::post('/post/{post}/comments', 'CommentController@store');

And in store method on controller:

public function store(Post $post)
{
  // You have now access to $post model
}
p0t4t0's avatar

@morteza not to be rude but I am already aware of that. I am just noticing some people still use query strings over such URL structures with Laravel, and I'm wondering why.

thomaskim's avatar

Typically, any required parameters would be in the path. Any optional parameters (like filters) are query strings.

So, most people use query strings for paginations, sorting, filtering, searches, etc.

Snapey's avatar

If you are following restful principles then you would have specific routes like /edit and then add query strings for variant data that you need to pass to the same route rather than create new routes.

So, as thomaskim says, things like filters and paginators. You are still hitting the same resource but you have some additional information to pass along

jlrdw's avatar

Parameters or query string either way works.

Please or to participate in this conversation.