首页 > 编程开发 > PHP    日期:2020-11-05 / 浏览

1.通过url辅助函数(路由)生成:

location.href = "{{url('user/index2')}}";

或者:

location.href = "{{url::to('user/index2')}}";

2.通过别名(路由)生成,前提是在注册路由的时候要指定别名,

例如:

Route::get('user/index2',['as' => 'user/index2', 'uses' => 'UserController@index1']);

location.href = "{{route('user/index2')}}";

或者:

location.href = "{{URL::route('user/index2')}}";

3.通过控制器、方法名生成(路由不要指定别名,否则会报错!):

location.href = "{{action('UserController@index2',['id'=>1,'author'=>'admin'])}}";

或者:

location.href = "{{URL::action('UserController@index2',['id'=>1,'author'=>'admin'])}}";

当然2,3中携带的参数都可以在控制器中使用 Request $request 接受

以上这篇关于laravel模板中生成URL的几种模式总结就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持免费资源网。

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章