laravel 中url使用
laravel 辅助函数url()和asset()区别
https://laravel-admin.org/docs/zh/1.x/installation
url('img/home1/'),生成的链接:http://localhost/img/home1/
url("/posts/{$post->age}",['post' => 1, 'comment' => 3]) 生成的链接: http://www.blog.com/posts/20/1/3
url('img/home1/','test'),生成的链接:http://localhost/img/home1/test
url('img/edit',['id'=>$v->id]) 生成的链接: http://www.blog.com/news/edit/56 而不是http://www.blog.com/news/edit?id=56
url('img/home1/','test',true),生成的链接:https://localhost/img/home1/test
asset('img/home1/'),生成的链接:http://localhost/img/home1/
asset('img/home1/',true),生成的链接:https://localhost/img/home1/
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')}}";
route('shitu_luyou',['post' => 1, 'comment' => 3]) http://www.blog.com/shitu?post=1&comment=3
action()
通过控制器、方法名生成(路由不要指定别名,否则会报错!):
location.href = "{{action('UserController@index',['id'=>1,'author'=>'admin'])}}";
或者:location.href = "{{URL::action('UserController@index',['id'=>1,'author'=>'admin'])}}";