Route::get('/protected', function () {
return "This is a protected route";
})->middleware('auth:sanctum');
注意:在使用Laravel Sanctum的API中,需要添加以下头信息:
Accept: application/json
Authorization: Bearer {token}
其中,{token}需要替换为通过登录API获得的令牌。如需详细了解如何利用Laravel Sanctum保护API,请参阅官方文档:https://laravel.com/docs/8.x/sanctum#protecting-your-api