您的位置 首页 php

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模式的三种方法

文章地址:https://www.zhihuclub.com/25082.shtml

关于作者: 智云科技

热门文章

网站地图