Passing page URL parameter to controller in Laravel 5.2

喜欢而已 提交于 2020-01-01 15:03:21

问题


In my application I have a page it called index.blade, with route /index. In its URL, it has some get parameter like ?order and ?type.

I want to pass these $_get parameter to my route controller action, query from DB and pass its result data to the index page. What should I do?


回答1:


If you want to access the data sent from get or post request use

public function store(Request $request)
{
    $order = $request->input('order');
    $type = $request->input('type');
    return view('whatever')->with('order', $order)->with('type', $type);
}

you can also use wildcards.

Exemple link

website.dev/user/potato

Route

Route::put('user/{name}', 'UserController@show');

Controller

public function update( $name)
{
    User::where('name', $name)->first();
    return view('test')->with('user', $user);
}

Check the Laravel Docs Requests.



来源:https://stackoverflow.com/questions/37013941/passing-page-url-parameter-to-controller-in-laravel-5-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!