untymage's avatar

/search?q= Vs. /search/{query}

I wanted to define a route for search operation :

Route::get('/search', function (Request $request) {
    return Order::search($request->search)->get();
});

Or

Route::get('/search/{query}', function ($query) {
    return Order::search($query)->get();
});

Which one would you pick and why another one is bad ?

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

Query string; the query segment does not uniquely identify a Resource.

1 like
martinbean's avatar

@untymage The first one (/search?q=foo) is the example of a query string. The clue is in the name: query string. You use query strings to query a resource and filter its results.

1 like

Please or to participate in this conversation.