Route::group(['middleware'=>'api'],function(){
Route::get('/api/tasks', function () {
return \App\Task::all();
});
Route::get('/api/task/{id}', function ($id) {
return \App\Task::find($id);
});
Route::post('/api/task/create', function () {
return \App\Task::all();
});
});
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'api' => \Barryvdh\Cors\HandleCors::class,
];
Route::group(['middleware'=>'api'],function(){
Route::get('/api/tasks', function () {
return \App\Task::all();
});
Route::get('/api/task/{id}', function ($id) {
return \App\Task::find($id);
});
Route::post('/api/task/create', function () {
});
});
我用的是5.1这么写的