我正在通过在线课程学习 Livewire 框架,为了学习我创建了一个测试项目。
在这个项目的一部分中,我有一个不提交的表单并且视图刷新但显然代码没有任何问题。
在单击提交按钮并刷新'a?添加到网址。
我的表格:
<form wire:submit.prevent="register">
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-user"></i> </span>
</div>
<input wire:model.lazy='name' class="form-control" placeholder="Full name" type="text">
</div> <!-- form-group// -->
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-envelope"></i> </span>
</div>
<input wire:model.lazy='email' class="form-control" placeholder="Email address" type="email">
</div> <!-- form-group// -->
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-lock"></i> </span>
</div>
<input wire:model.lazy='password' class="form-control" placeholder="Create password" type="password">
</div> <!-- form-group// -->
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-lock"></i> </span>
</div>
<input wire:model.lazy='ConfirmPassword' class="form-control" placeholder="Repeat password" type="password">
</div> <!-- form-group// -->
<div class="form-group">
<button class="btn btn-primary" type="submit" >
create account
<div wire:loading>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
</div>
</button>
</div>
</form>
我的组件:
class Register extends Component
{
public $name,$email,$password,$ConfirmPassword;
public function register(){
dd('dul');
$this->validate([
'name'=>'required|string',
'email'=>'required|email|unique:users,email',
'password'=>'required|string|min:8|same:ConfirmPassword',
]);
User::create([
'user'=>$this->name,
'email'=>$this->email,
'password'=>Hash::make($this->password),
]);
session()->flash('success','registration done successfuly');
}
public function render()
{
return view('livewire.auth.register');
}
}
我的路线:
<?php
use App\Http\Livewire\Post\Index as INdexPost;
use App\Http\Livewire\Auth\Index as IndexAuth;
use App\Http\Livewire\Auth\Register ;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('index');
});
Route::get('/post', IndexPost::class);
Route::get('/auth', IndexAuth::class);