laravel-路由大集合

Route::get(’/’, function () {
return view(‘welcome’);
});
/*

  • response
  • text/html text/plain
    /
    Route::get(‘hello’,function (){
    return response([“1”,1],201)->header(‘content-type’,‘text/plain’);
    });
    /
  • 文件下载
    //
    Route::get(‘h1’,function (){
    return response()->download(“index.php”,‘my.php’);
    });
    /
  • 路由跳转到外部
    //
    Route::get(‘h2’,function (){
    return redirect(“http://www.baidu.com”);
    });
    Route::get(‘h3’,function (){
    return redirect(“login”);
    });
    /
  • 路由跳转到内部
    *//
    Route::get(‘test’,“Test\TestController@index”);
    Route::post(‘t1’,“Test\TestController@t1”);

/*

  • 正则
    *//
    Route::get(“t2/{n}/{p}/{w?}”,function ( n , n, n,p){
    return ‘n:’. n . " − p : " . n."-p:". n."p:".p;
    })->where(
    [
    ‘n’=>’\d+’,
    ‘p’=>’[a-z]+’,
    ‘w’=>’(\w+.html)|(\w+)’
    ]
    );
    Route::match([‘get’,‘post’],‘login’,“Admin\LoginController@login”)->name(‘login’);
    Route::group([‘prefix’=>‘t’],function (){
    Route::get(‘t1’,function (){
    return array(1,2,3,4,5);
    });
    });
    Route::group([‘prefix’=>‘s’,‘middleware’=>‘auth’,‘namespace’=>‘aa’],function (){
    Route::get(‘s1’,function (){
    return ‘auth.s’;
    });
    });

/*

  • 资源型
  • artisan make:controller Admin\UserController --resource
    */
    //Route::namespace(“Admin”)->resource(“u”,“UserController”);
    Route::group([‘namespace’=>“Admin”,“prefix”=>“admin”],function (){
    Route::middleware(“auth”)->resource(“u”,“UserController”)->only([‘index’]);
    Route::middleware(“auth”)->resource(“u”,“UserController”)->except([‘show’]);
    });

/*

  • api型php artisan make:controller Admin/ApiController --api
    */
    Route::group([‘namespace’=>“Admin”,“prefix”=>“i”],function (){
    Route::apiResources([“a”=>“ApiController”]);
    });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值