Laravel 9 身份验证显示错误(已解决)
Laravel 9 authentication showing error (Solved)
我已经创建了一个登录路由并且它工作正常,但是当尝试存储经过身份验证的用户的数据时它显示一个错误,不支持 GET 方法但我正在使用 POST 方法。但它正在获取以下 URL 作为 GET 方法。
"http://127.0.0.1:8000/api/login"
The GET method is not supported for this route. Supported methods:
POST.
我的登录路径
Route::post('/login',[UserController::class,'login'])->name('login');
登录后响应
{
"person": {
"_token": "WBHtlTsFtJOSdWx28nHMbtbQyUBB1vkSTjkhpb8t",
"first_name": "Navid",
"last_name": "Anjum",
"email": "nav@gmail.com",
"password": "11111111"
}
}
路由插入数据
Route::post('page/create',[PageController::class,'store'])
->middleware('auth:api')->name('page.create');
php artisan cache:clear
php artisan route:cache
php artisan config:cache
php artisan view:clear
我已经用 Laravel sanctum 修复了它。
Route::group(['middleware' => ['auth:sanctum']], function () {
Route::post('page/create',[PageController::class,'store'])->name('page.create');
Route::post('page/post',[PostController::class,'store'])->name('post.create');
Route::post('/page/{pageId}/attach-post',[PostController::class,'from_page'])->name('page.post');});
在 httm->kernel sanctum 中被评论 out.So 这就是为什么我之前尝试使用它时它不起作用的原因。
'api' => [
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
我已经创建了一个登录路由并且它工作正常,但是当尝试存储经过身份验证的用户的数据时它显示一个错误,不支持 GET 方法但我正在使用 POST 方法。但它正在获取以下 URL 作为 GET 方法。
"http://127.0.0.1:8000/api/login"
The GET method is not supported for this route. Supported methods: POST.
我的登录路径
Route::post('/login',[UserController::class,'login'])->name('login');
登录后响应
{
"person": {
"_token": "WBHtlTsFtJOSdWx28nHMbtbQyUBB1vkSTjkhpb8t",
"first_name": "Navid",
"last_name": "Anjum",
"email": "nav@gmail.com",
"password": "11111111"
}
}
路由插入数据
Route::post('page/create',[PageController::class,'store'])
->middleware('auth:api')->name('page.create');
php artisan cache:clear
php artisan route:cache
php artisan config:cache
php artisan view:clear
我已经用 Laravel sanctum 修复了它。
Route::group(['middleware' => ['auth:sanctum']], function () {
Route::post('page/create',[PageController::class,'store'])->name('page.create');
Route::post('page/post',[PostController::class,'store'])->name('post.create');
Route::post('/page/{pageId}/attach-post',[PostController::class,'from_page'])->name('page.post');});
在 httm->kernel sanctum 中被评论 out.So 这就是为什么我之前尝试使用它时它不起作用的原因。
'api' => [
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],