简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM