当我提交表单时,我得到的密码为空,但我正在插入它。(Laravel Livewire)
迁移文件(这是迁移文件)
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(){
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('users');
}
};
模型类(这是模型类)
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Livewire 类(这是 Livewire 类)
<?php
namespace App\Http\Livewire;
use Illuminate\Support\Facades\Auth;
use Hash;
use App\Models\User;
use Livewire\Component;
class Authenticate extends Component
{
public $name,$email,$password,$register = false,$login = true;
public $rules = [
'email' => 'required',
'password' => 'required',
];
public function resetInputFields(){
$this->name = null;
$this->email = null;
$this->password = null;
}
public function render()
{
return view('livewire.authenticate')
->layout('layouts.auth');
}
public function login()
{
$this->validate();
if(Auth::attempt(['email' => $this->email,'password' => $this->password]))
{
session()->flash('success','Login Successfully');
}else{
session()->flash('error','Login Failed');
}
}
public function register()
{
$this->register = !$this->register;
$this->login = !$this->login;
}
public function store()
{
$this->validate([
'name' => 'required',
'email' => 'required|email',
'password' => 'required',
]);
User::create([
'name' => $this->name,
'email' => $this->email,
'password' => $this->password,
]);
session()->flash('success','Registered Successfully');
$this->resetInputFields();
}
}
刀片文件(这是我的 html 文件)
@if(session()->has('error'))
{{session('error')}}
@elseif(session()->has('success'))
{{session('success')}}
@endif
@if($register)
<form class="login100-form" wire:submit.prevent="store">
<span class="login100-form-title">
Member Register
</span>
<div class="wrap-input100 ">
<input class="input100" type="text" placeholder="Name" wire:model="name">
<span class="focus-input100"></span>
<span style="color:red">@error('name'){{$message}}@enderror</span>
<span class="symbol-input100">
<i class="fa fa-user" aria-hidden="true"></i>
</span>
</div>
<div class="wrap-input100 ">
<input class="input100" type="email" placeholder="Email" wire:model="email">
<span class="focus-input100"></span>
<span style="color:red">@error('email'){{$message}}@enderror</span>
<span class="symbol-input100"><i class="fa fa-envelope" aria-hidden="true"></i></span>
</div>
<div class="wrap-input100 ">
<input class="input100" type="password" placeholder="Password" wire:model="password">
<span class="focus-input100"></span>
<span style="color:red">@error('password'){{$message}}@enderror</span>
<span class="symbol-input100"><i class="fa fa-lock" aria-hidden="true"></i></span>
</div>
<div class="container-login100-form-btn">
<button class="login100-form-btn" type="submit">Register</button>
</div>
<div class="text-center p-t-136">
<button class="txt2" wire:click.prevent="register">Already have an account?
<i class="fa fa-long-arrow-right m-l-5" aria-hidden="true"></i>
</button>
</div>
</form>
@else
<form class="login100-form" wire:submit.prevent="login">
<span class="login100-form-title">
Member Login
</span>
<div class="wrap-input100">
<input class="input100" type="text" wire:model="email">
<span class="focus-input100"></span>
<span style="color:red">@error('email'){{$message}}@enderror</span>
<span class="symbol-input100">
<i class="fa fa-envelope" aria-hidden="true"></i>
</span>
</div>
<div class="wrap-input100">
<input class="input100" type="password" wire:model="password">
<span class="focus-input100"></span>
<span style="color:red">@error('password'){{$message}}@enderror</span>
<span class="symbol-input100">
<i class="fa fa-lock" aria-hidden="true"></i>
</span>
</div>
<div>
<label>Remember me</label>
<input type="checkbox" name="remember_me" value="1">
</div>
<div class="container-login100-form-btn">
<button class="login100-form-btn" type ="submit">
Login
</button>
</div>
<div class="text-center p-t-12">
<span class="txt1">
Forgot
</span>
<a class="txt2" href="#">
Password?
</a>
</div>
<div class="text-center p-t-36">
<button class="txt2" wire:click.prevent="register">
Create your Account
<i class="fa fa-long-arrow-right m-l-5" aria-hidden="true"></i>
</button>
</div>
</form>
@endif
我有拼写错误的交叉检查,但每件事都找到了。我没有得到问题