找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 查看内容

Laravel生成url模式的三种方法

作者:模板之家 2021-6-3 21:48 159人关注

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

下面由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模式的三种方法的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章!


路过

雷人

握手

鲜花

鸡蛋
来自: 网络收集

全部回复(0)