下面由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模式的三种方法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号