下面由laravel教程栏目给大家介绍laravel生成url模式的三种方法,希望对需要的朋友有所帮助!

Laravel 生成url模式
1、通过url辅助函数(路由)生成
location.href = "{{url('main/index')}}";location.href = "{{url::to('main/index')}}";
2.通过别名(路由)生成
前提是在注册路由的时候要指定别名,例如:Route::get(‘main/index’,[‘as’ => ‘main/index’, ‘mains’ => ‘MainController@index’]);
location.href = "{{route('main/index')}}";location.href = "{{URL::route('main/index')}}";
3.通过控制器、方法名生成(路由不能指定别名):
location.href = "{{action('UserController@index',['id'=>1,'author'=>'admin'])}}";location.href = "{{URL::action('UserController@index',['id'=>1,'author'=>'admin'])}}";
注:2,3中携带的参数都可以在控制器中使用 Request $request 接收
以上就是Laravel生成url模式的三种方法的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/76570.html
微信扫一扫
支付宝扫一扫