简体   繁体   English

如何在url(laravel 5.3)中获取参数?

[英]How to get parameter in url (laravel 5.3)?

My url is like this : http://localhost/mysystem/public/users/index/2016 我的网址是这样的: http://localhost/mysystem/public/users/index/2016

I want to get 2016 , because I need it. 我想要2016 ,因为我需要。 But, I'm confused 但是,我很困惑

Is there any people who can help me? 有没有人可以帮助我?

In your previous question I can see this method: 在您之前的问题中,我可以看到此方法:

public function store(CreateUserRequest $request)

And your route should look like this (partially taken from previous answer too): 而且您的路线应如下所示(也部分取自之前的答案):

Route::get('users/store/{year}', 'UserController@store')->name('users.store.year');

Note, that if you'll build store method with Route::resource() , you'll not be able to pass year through URL. 请注意,如果要使用Route::resource()构建store方法,将无法通过URL传递年份。

So, to make it work you need to set route and to change method to this: 因此,要使其正常工作,您需要设置路由并更改此方法:

public function store(CreateUserRequest $request, $year)

$year variable will have 2016 value. $year变量的值将为2016

To get 2016 , you can use $year = Request::segment(3); 要获得2016 ,可以使用$year = Request::segment(3); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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