laravel模板中生成URL的幾種模式

2012013977發表於2017-08-14
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 接受

相關文章