laravel框架的使用1---路由

  /*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!!";
  });
  });
  */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值