Reputation:
I'm working with Laravel 8 to develop my project and I have built this form for verifying token:
<div class="card-body">
<form action="{{ route('profile.2fa.phone') }}" method="POST">
@csrf
<div class="form-group">
<label for="token" class="col-form-label">Token</label>
<input type="text" class="form-control @error('token') is-invalid @enderror" name="token" placeholder="enter your token">
@error('token')
<span class="invalid-feedback">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="form-group">
<button class="btn btn-primary">Validate token</button>
</div>
</form>
</div>
And then at web.php
I have these routes:
Route::get('/settings/twofactor/phone' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'getPhoneVerify']);
Route::post('/settings/twofactor/phone' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'postPhoneVerify'])->name('profile.2fa.phone');
But now when I add the token and press the Validate Token button, I get this error:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: POST.
So what is going wrong here? How can I solve this issue?
I would really appreciate any idea or suggestion from you guys...
Thanks in advance.
Here are all routes:
Route::get('/', function () {
return view('welcome');
});
Route::prefix('admin')->middleware(['auth', 'verified'])->group(function() {
Route::get('/', function () {
return view('admin.index');
});
Route::resource('users' , App\Http\Controllers\Admin\AdminUserController::class)->middleware('admin');
Route::get('/settings', [App\Http\Controllers\Admin\AdminSettingsController::class, 'index'])->name('profile');
Route::post('/settings/twofactor' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'postManageTwoFactor'])->name('profile.2fa.manage');
Route::get('/settings/twofactor/phone' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'getPhoneVerify']);
Route::post('/settings/twofactor/phone' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'postPhoneVerify'])->name('profile.2fa.phone');
Route::get('/auth/token' ,[App\Http\Controllers\Auth\AuthTokenController::class, 'getToken'])->name('2fa.token');
Route::post('/auth/token' ,[App\Http\Controllers\Auth\AuthTokenController::class, 'postToken']);
});
Auth::routes(['verify' => true]);
Route::get('/auth/google', [App\Http\Controllers\Auth\GoogleAuthController::class, 'redirect'])->name('auth.google');
Route::get('/auth/google/callback', [App\Http\Controllers\Auth\GoogleAuthController::class, 'result']);
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Upvotes: 1
Views: 19802
Reputation: 1
button type="submit" class="btn btn-dark">sent This button solve your problem put this button in your form
Upvotes: 0
Reputation: 11
I think your problem will solve if you try this one, just change the following line of your code with this one.
<button type="submit" class="btn btn-primary">Validate token</button>
Upvotes: 0
Reputation: 223
If you have routes like /users/posts/
, /users/posts/create
, and /users/posts/edit
then create and edit routes should be written before /users/posts
to avoid route conflict problem.
In your routes web.php
, change the following routes order:
Route::get('/', function () {
return view('welcome');
});
Route::prefix('admin')->middleware(['auth', 'verified'])->group(function() {
Route::get('/', function () {
return view('admin.index');
});
Route::resource('users' , App\Http\Controllers\Admin\AdminUserController::class)->middleware('admin');
Route::get('/settings/twofactor/phone' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'getPhoneVerify']);
Route::post('/settings/twofactor/phone' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'postPhoneVerify'])->name('profile.2fa.phone');
Route::post('/settings/twofactor' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'postManageTwoFactor'])->name('profile.2fa.manage');
Route::get('/settings', [App\Http\Controllers\Admin\AdminSettingsController::class, 'index'])->name('profile');
Route::get('/auth/token' ,[App\Http\Controllers\Auth\AuthTokenController::class, 'getToken'])->name('2fa.token');
Route::post('/auth/token' ,[App\Http\Controllers\Auth\AuthTokenController::class, 'postToken']);
});
Auth::routes(['verify' => true]);
Route::get('/auth/google/callback', [App\Http\Controllers\Auth\GoogleAuthController::class, 'result']);
Route::get('/auth/google', [App\Http\Controllers\Auth\GoogleAuthController::class, 'redirect'])->name('auth.google');
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Upvotes: 2