我正在使用Laravel 5.2进行项目。*我正在使用默认的auth控制器和视图。我的最终目标是在1页上有2个表格进行注册。当用户注册时,他们可以注册为提供者或普通用户。我在'users'数据库中创建了一个名为'provider'的新列。
我也在使用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>
然后在Auth \ AuthController中我编辑了'create'函数来添加'provider'布尔值:
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个单独的注册页面,一个用于“Family”,另一个用于“Provider”,同时仍然使用默认的AUTH系统?我之前尝试过,只要有验证问题,它就会一直重定向到/ auth / register
感谢您的帮助:)
答案 0 :(得分:0)
显然我忘了添加&#39;提供商&#39;用户模型中的$ fillable ..
我已经解决了自己的问题,但如果有更好的方法可以做到这一点,我很乐意学习!
应用\ user.php的:
protected $fillable = [ 'name', 'provider', 'email', 'password' ];