我試圖通過使用模態窗口和添加一些新字段來修改laravel的默認身份驗證系統。 所以,我有一個模式窗口註冊新用戶,看起來像這樣:Laravel默認身份驗證與模式
<!-- Modal Register area -->
<div class="modal fade" id="registerModal" tabindex="-1" role="dialog" aria-labelledby="myRegisterLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="formRegister" class="login-form" action="{{ route('register') }}" method="POST">
{{ csrf_field() }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myRegisterLabel">Sign Up</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>First Name:</label>
<input type="text" name="first_name" placeholder="first name..." value="{{ old('first_name') }}" required autofocus>
</div>
<div class="form-group">
<label>Last Name:</label>
<input type="text" name="last_name" placeholder="last name..." value="{{ old('last_name') }}" required autofocus>
</div>
<div class="form-group">
<label>Email:</label>
<input type="email" name="email" placeholder="email..." value="{{ old('email') }}" required>
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" name="password" required>
</div>
<div class="form-group">
<label>Password Confirmation:</label>
<input type="password" name="password_confirmation" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</form>
@if(count($errors))
@foreach ($errors->all() as $error)
<div class="alert alert-danger">
<p>{{ $error }}</p>
</div>
@endforeach
@endif
</div>
</div>
</div>
<!-- End Modal Register area -->
然後我修改了RegisterController驗證規則和創建方法,包括這個新的領域以及遷移文件。 (所以,我在數據庫中的Fileds,一切都很好有)
RegisterController:
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
在形式,你可以看到我張貼這種路由(「註冊」),但即使我沒有得到任何錯誤,當我提交表單,我得到重定向到/用戶沒有得到保存在數據庫.. 事情是,我不太確定這個默認身份驗證系統如何工作..
感謝您的幫助!
你的字段添加到您的$可填寫財產上的模型? –
是的,我做了,我忘了提及。 –
因此,在您製作和創建時,您添加的新字段在哪裏? –