Sorry, I have a routes problem in laravel livewire. I want to test my login form validation on my website by sending empty input and continuously clicking the submit button (after giving a response of course), and on the fifth (5) click I have a problem “The GET method is not supported for this route. Supported methods: POST”. Does anyone know about this problem? Because I also tried it on a simple form on localhost and there was no error.
I use laravel livewire 2.2
Routes code
Route::group(['prefix' => 'livewire'], function() {
Route::get('/login',Login::class);
Route::get('/add',Add::class);
});
Blade
<form wire:submit.prevent="check">
<div class="form-group">
<label class="label">Email</label>
<div class="input-group">
<input wire:model.defer="email" type="email" class="form-control" placeholder="[email protected]">
<div class="input-group-append">
<span class="input-group-text">
<i class="mdi mdi-check-circle-outline"></i>
</span>
</div>
</div>
@error('email')<label class="text-danger">{{ $message }}</label> @enderror
</div>
<div class="form-group">
<label class="label">Password</label>
<div class="input-group">
<input wire:model.defer="password" type="password" class="form-control" placeholder="**********">
<div class="input-group-append">
<span class="input-group-text">
<i class="mdi mdi-check-circle-outline"></i>
</span>
</div>
</div>
@error('password')<label class="text-danger">{{ $message }}</label> @enderror
</div>
<div class="form-group">
<button class="btn btn-success submit-btn btn-block" wire:loading.attr="disabled" >
<div wire:loading.remove>Login</div>
<div wire:loading>
<div class="loading-bar bg-white"></div>
<div class="loading-bar bg-white"></div>
<div class="loading-bar bg-white"></div>
<div class="loading-bar bg-white"></div>
</div>
</button>
</div>
</form>
Controllers
class Login extends Component
{
public $password;
public $email;
protected $rules = [
'password' => 'required',
'email' => 'required|email',
];
public function check()
{
$this->validate($this->rules);
if (Auth::attempt(['email' => $this->email, 'password' => $this->password]))
{
redirect()->to('livewire/add');
}else
{
$this->dispatchBrowserEvent('alert', ['type' => 'error', 'title' => 'Error','message' => 'Credential not valid']);
}
}
public function render()
{
return view('livewire.login')->extends('backend.v2.master');
}
}
Error result
Thanks for your help