吴环宇
吴环宇

Reputation: 467

About Laravel get method routing

Can laravel support such get method routing?

Route::get('/users/{id}/posts?num={num}','SomeController@SomeMethod');

Here,id is a parameter in url and num is another parameter appended after url. SomeMethod accept two parameters id and num.
I did do some google.But all I got is about

Route::get('/users/{id}/posts/{num}','SomeController@SomeMethod');

Can laravel support such get routing?

Upvotes: 1

Views: 40

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163778

Yes it does. Change the route to:

Route::get('/users/{id}/posts','SomeController@someMethod');

You controller method will look like this:

public function someMethod($id)
{
    $num = request('num');

Then URL like this one will pass to the method and you'll get values of id and num:

/users/2/posts?num=78

Upvotes: 1

Related Questions