1
我正在使用Laravel 5.2。*進行項目工作,我正在使用默認的認證控制器和視圖。我的最終目標是在1頁上有2個表格用於註冊。當用戶註冊時,他們可以註冊爲提供商或普通用戶。我在'用戶'數據庫中創建了一個名爲'provider'的新列。Laravel 5.2多種形式註冊頁面
我還使用LaravelCollective HTML/Forms來生成表單。
我創建的視圖兩種形式:
<div class="row">
<div class="col-md-6">
<h2>Family Form</h2>
{!! Form::open() !!}
{{ Form::label('name', "Name:") }}
{{ Form::text('name', null, ['class' => 'form-control']) }}
{{ Form::hidden('provider', false) }}
{{ Form::label('email', "Email:") }}
{{ Form::text('email', null, ['class' => 'form-control']) }}
{{ Form::label('password', "Password:") }}
{{ Form::password('password', ['class' => 'form-control']) }}
{{ Form::label('password_confirmation', "Confirm Password:") }}
{{ Form::password('password_confirmation', ['class' => 'form-control']) }}
{{ Form::submit('Register', ['class' => 'btn btn-primary btn-block form-spacing-top']) }}
{!! Form::close() !!}
</div>
<div class="col-md-6">
<h2>Provider Form</h2>
{!! Form::open() !!}
{{ Form::label('name', "Name:") }}
{{ Form::text('name', null, ['class' => 'form-control']) }}
{{ Form::hidden('provider', true) }}
{{ Form::label('email', "Email:") }}
{{ Form::text('email', null, ['class' => 'form-control']) }}
{{ Form::label('password', "Password:") }}
{{ Form::password('password', ['class' => 'form-control']) }}
{{ Form::label('password_confirmation', "Confirm Password:") }}
{{ Form::password('password_confirmation', ['class' => 'form-control']) }}
{{ Form::submit('Register', ['class' => 'btn btn-primary btn-block form-spacing-top']) }}
{!! Form::close() !!}
</div>
</div>
,然後在驗證\ AuthController我編輯了「創建」功能添加「提供商」布爾:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'provider' => $data['provider'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
現在我的問題是,無論我填寫什麼表格,總是在'提供者'下的數據庫中保存爲FALSE或'0'
這裏是表格的HTML輸出:
<div class="row">
<div class="col-md-6">
<h2>Family Form</h2>
<form method="POST" action="//localhost:3000/auth/register" accept-charset="UTF-8"><input name="_token" type="hidden" value="Rli5AmRKkov64hPt6AEfr7yOLwA5EwUmozVePgQL">
<label for="name">Name:</label>
<input class="form-control" name="name" type="text" id="name">
<input name="provider" type="hidden" value="">
<label for="email">Email:</label>
<input class="form-control" name="email" type="text" id="email">
<label for="password">Password:</label>
<input class="form-control" name="password" type="password" value="" id="password">
<label for="password_confirmation">Confirm Password:</label>
<input class="form-control" name="password_confirmation" type="password" value="" id="password_confirmation">
<input class="btn btn-primary btn-block form-spacing-top" type="submit" value="Register">
</form>
</div>
<div class="col-md-6">
<h2>Provider Form</h2>
<form method="POST" action="//localhost:3000/auth/register" accept-charset="UTF-8"><input name="_token" type="hidden" value="Rli5AmRKkov64hPt6AEfr7yOLwA5EwUmozVePgQL">
<label for="name">Name:</label>
<input class="form-control" name="name" type="text" id="name">
<input name="provider" type="hidden" value="1">
<label for="email">Email:</label>
<input class="form-control" name="email" type="text" id="email">
<label for="password">Password:</label>
<input class="form-control" name="password" type="password" value="" id="password">
<label for="password_confirmation">Confirm Password:</label>
<input class="form-control" name="password_confirmation" type="password" value="" id="password_confirmation">
<input class="btn btn-primary btn-block form-spacing-top" type="submit" value="Register">
</form>
</div>
</div>
如果沒有辦法支持同一註冊頁面兩種形式,有沒有一種方法來創建2個獨立的寄存器頁,一個「家庭」和一個「提供者」,同時仍然使用默認的身份驗證系統?我試過不過前面只要有一個驗證問題將始終重定向到/認證/註冊
感謝您的幫助:)
什麼是供應商領域的在你的數據庫中的數據類型? –
就我所見,兩種形式的字段都是相同的(?)。爲什麼你希望他們成爲兩種形式,那麼首先,爲什麼不簡單地使用單選按鈕讓用戶選擇一種形式_他們想要註冊哪種類型的賬戶? – CBroe
@TheAlpha是布爾型 –