Laravel如何实现生成URL模式的三种方法?
- 内容介绍
- 文章标签
- 相关推荐
本文共计294个文字,预计阅读时间需要2分钟。
Laravel生成URL模式的三种方法介绍,希望对需要的朋友有所帮助!
1. Laravel生成URL模式方法一:通过路由生成phplocation.href={{ url('main/index') }};
2. Laravel生成URL模式方法二:通过URL辅助函数生成phplocation.href={{ route('main.index') }};
3. Laravel生成URL模式方法三:直接使用URL方法phplocation.href={{ url('main/index') }};
下面由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模式的三种方法的详细内容,更多请关注自由互联其它相关文章!
本文共计294个文字,预计阅读时间需要2分钟。
Laravel生成URL模式的三种方法介绍,希望对需要的朋友有所帮助!
1. Laravel生成URL模式方法一:通过路由生成phplocation.href={{ url('main/index') }};
2. Laravel生成URL模式方法二:通过URL辅助函数生成phplocation.href={{ route('main.index') }};
3. Laravel生成URL模式方法三:直接使用URL方法phplocation.href={{ url('main/index') }};
下面由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模式的三种方法的详细内容,更多请关注自由互联其它相关文章!

