在 Laravel 中返​​回带有参数的视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31374652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:56:13  来源:igfitidea点击:

return view with parameters in laravel

phplaravellaravel-5

提问by Joe

I have a return in my controller like this:

我的控制器中有这样的回报:

    return view('frontend.bike')->with('message', 'Bike Created');

It directs correctly view, however I want to pass it two variables that are needed. Currently I have it routing via:

它可以正确引导视图,但是我想将两个所需的变量传递给它。目前我通过以下方式路由:

Route::get('b/{bikename}/{type?}', ['as' => 'bike', 'uses' => 'FrontendController@bike']);

How can I include a bikename and type to the return to make sure it goes to the correct page.

如何在退货单中包含自行车名称并键入以确保它进入正确的页面。

回答by pinkal vansia

you can get those route variable in controller as below in function arguments,

您可以在控制器中获取这些路由变量,如下所示在函数参数中,

public function bike($bikename, $type = null){

    $type = $type ? $type:'N/A'; //optional
    $message = 'Bike Created';
    return view('frontend.bike', compact('message', 'bikename', 'type'));
}

in views/frontend/bike.blade.php,

在视图/前端/bike.blade.php,

{{ $message }}
{{ $bikename }}
{{ $type }}