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”]);
});