## 开整

### 注册先行

#### 创建组件

 1  ./vendor/bin/sail artisan make:livewire Auth/Register 

#### 定义路由

 1  Route::get('/register', \App\Http\Livewire\Auth\Register::class); 

#### 编辑页面

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55  

{{-- To attain knowledge, add things every day; To attain wisdom, subtract things every day. --}}
@error('email') @enderror
@error('name') @enderror


#### 组件部分

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53   'required|min:6|unique:users', 'email' => 'required|email|unique:users', 'password' => ['required', 'confirmed', Password::min(8)->mixedCase()->numbers()->symbols()], 'password_confirmation' => 'required', ]; } public function updated($propertyName) {$this->validateOnly($propertyName); // 如果输入的是密码字段，需要跟验证字段同时验证 if (in_array($propertyName, ['password', 'password_confirmation'])) { $this->validateOnly('password_confirmation');$this->validateOnly('password'); } } public function register() { $this->validate();$res = User::create([ 'name' => $this->name, 'email' =>$this->email, 'password' => \Hash::make($this->password), ]); dd($res); } public function render() { return view('livewire.auth.register'); } } 

## 总结

demo 项目地址：livewire-demo