对不起,我在laravel livewire中遇到路由问题。我想通过连续点击提交按钮(当然是在给出回复后(在我的网站上测试我的登录表单验证,在第五(5(次点击时我有问题";此路由不支持GET方法。支持的方法:POST";。有人知道这个问题吗?因为我也在localhost上的一个简单表单上尝试过,没有出现错误。
我使用laravel livewire 2.2
这是我的网站上的代码
刀片
<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="xxx@xxx.xx">
<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>
控制器
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');
}
}
路由
Route::group(['prefix' => 'livewire'], function() {
Route::get('/login',Login::class);
Route::get('/add',Add::class);
});
首次提交
图像
第五次点击后的错误结果
图像
谢谢你的帮助。
您是否尝试过将整个表单包装在div元素中?
<div>
{{-- Anything you want to do --}}
</div>