laravel框架的使用1---路由
来源:互联网 发布:化妆品淘宝批发 编辑:程序博客网 时间:2024/06/07 14:41
/*1、含有对应的方法的路由 * Route::match(['get', 'post'], '/', function () { return 'Hello World'; }); */ /*2、含有foo为控制器的路由 * Route::any('foo', function () { return 'Hello World'; }); */ /* * 3、传参路由,必须有参数 * Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) { // }); */ /*4、可选参数路由 * Route::get('user/{name?}', function ($name = null) { return $name; }); Route::get('user/{name?}', function ($name = 'John') { return $name; }); */ /*5、参数正则匹配路由 * Route::get('user/{id}/{name}', function ($id, $name) { // }) ->where(['id' => '[0-9]+', 'name' => '[a-z]+']);*/ /* * 6、RouteServiceProvider中的boot方法可以定义公共的参数正则匹配,如下: * public function boot(Router $router) { $router->pattern('id', '[0-9]+'); parent::boot($router); } Route::get('user/{id}', function ($id) { return $id; }); */ /* * 7、给路由一个别名(貌似是) * Route::get('user/profile', ['as' => 'profile', function () { // }]); 可以这样使用 Route::match(['get', 'post'], '/', function () { return redirect()->route('profile'); }); */ /* * 8、路由组的设计规则 * Route::group(['as' => 'admin::'], function () { Route::get('dashboard', ['as' => 'dashboard', function () { // Route named "admin::dashboard" return "Test Group!"; }]); }); 这样使用: Route::get('user/profile', ['as' => 'profile', function () { return redirect()->route("admin::dashboard"); }]); */ /* * 9、调用route方法传参 * Route::get('user/{id}/profile', ['as' => 'profile', function ($id) { // }]); $url = route('profile', ['id' => 1]); */ /* * 10、Middleware中间件的使用 Route::group(['middleware' => 'auth'], function () { Route::get('/', function () { // Uses Auth Middleware }); Route::get('user/profile', function () { // Uses Auth Middleware }); }); 所有组中的请求都会先跳转到auth中 */ /* * 11、使用命名空间 * Route::group(['namespace' => 'Admin'], function() { // Controllers Within The "App\Http\Controllers\Admin" Namespace Route::group(['namespace' => 'User'], function() { // Controllers Within The "App\Http\Controllers\Admin\User" Namespace }); }); */ /* * 12、使用下面方式可以获取当前的域名信息 * Route::group(['domain' => '{account}.myapp.com'], function () { Route::get('user/{id}', function ($account, $id) { return "Account:".$account.";"."Id:".$id; }); }); */ /* * 13、给路由增加前缀 * Route::group(['prefix' => 'admin'], function () { Route::get('users', function () { // Matches The "/admin/users" URL }); }); 或者这样 Route::group(['prefix' => 'accounts/{account_id}'], function () { Route::get('detail', function ($account_id) { // Matches The accounts/{account_id}/detail URL return "Detail!!"; }); }); */
0 0
- laravel框架的使用1---路由
- laravel框架无法访问‘/’之外的路由解决方法
- laravel框架的使用
- Laravel框架的redis使用1
- laravel 路由使用(二)
- laravel框架学习-配置,路由
- laravel框架学习(路由)
- Laravel框架路由配置、设置
- Laravel的路由管理
- laravel 路由的demo
- 4. laravel 路由(1)
- laravel(六)laravel路由使用
- laravel学习笔记(1)— Laravel的安装及laravel中的路由介绍
- httprouter框架 (Gin使用的路由框架)
- php Laravel框架学习(三) 之 路由
- Laravel框架学习-1.初探路由
- Laravel 框架指定路由关闭 csrf
- Laravel框架中验证码的使用
- HDU 1061 Rightmost Digit(快速幂)
- 扑克牌大小(华为16年研发试题)
- Eclipse插件开发GEF
- 给listView添加headView或footView不显示的问题
- HttpURLConnection与HttpClient区别及联系
- laravel框架的使用1---路由
- opengl es2 创建两个三角形
- 欢迎使用CSDN-markdown编辑器
- php-进度条 ob_flush() 的使用
- BZOJ 2503 相框 并查集
- Xamarin.Forms 之 样式Styles
- java.lang.SecurityException: ConnectivityService: Neither user 10086 nor current process has android
- WebDriverException: Message: Failed to navigate to http://10.1.96.59:9080解决办法
- iOS开发-C语言-指针