laravel 中url使用

url()

通过url辅助函数(路由)生成:
location.href = "{{url('user/index')}}";

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

 

route()

通过别名(路由)生成,前提是在注册路由的时候要指定别名,例如:Route::get('user/index',['as' => 'user/index1', 'uses' => 'UserController@index']);
location.href = "{{route('user/index1')}}";

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

 

action()

通过控制器、方法名生成(路由不要指定别名,否则会报错!):
location.href =  "{{action('UserController@index',['id'=>1,'author'=>'admin'])}}";
或者:location.href =  "{{URL::action('UserController@index',['id'=>1,'author'=>'admin'])}}";

posted @ 2018-09-06 09:29  $wanggang  阅读(4607)  评论(0编辑  收藏  举报