Laravel 5.1 AuthController 用户注册唯一随机id
Laravel 5.1 AuthController user registration unique random id
所以我在生成唯一的完全随机的 customerid 时遇到了一些问题。
我尝试的所有操作都会在我的数据库中的客户 ID 位置给我一个空白列。谁能告诉我我做错了什么!
提前致谢这是我的代码:
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|max:255|unique:gebruikers',
'email' => 'required|max:255|unique:gebruikers',
'password' => 'required|confirmed|min:6',
'customerid' => 'unique:gebruikers'
]);
}
和
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'customerid' => str_random(30),
]);
}
和 register.blade.php :
<form method="POST" action="/auth/register">
{!! csrf_field() !!}
<div>
<input type="hidden" name="customerid">
Name
<input type="text" name="username" value="{{ old('username') }}">
</div>
<div>
Email
<input type="email" name="email" value="{{ old('email') }}">
</div>
<div>
Password
<input type="password" name="password">
</div>
<div>
Confirm Password
<input type="password" name="password_confirmation">
</div>
<div>
<button type="submit">Register</button>
</div>
</form>
错误的运算符“==”,将其替换为“=>”
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'customerid' => str_random(30),
]);
}
您是否在您的模型中提到了可填写的客户 ID? – Imtiaz Pabel
辛苦了谢谢!
使该字段在您的模型中可填写
protected $fillable = ['username', 'email', 'password', 'customerid'];
所以我在生成唯一的完全随机的 customerid 时遇到了一些问题。
我尝试的所有操作都会在我的数据库中的客户 ID 位置给我一个空白列。谁能告诉我我做错了什么!
提前致谢这是我的代码:
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|max:255|unique:gebruikers',
'email' => 'required|max:255|unique:gebruikers',
'password' => 'required|confirmed|min:6',
'customerid' => 'unique:gebruikers'
]);
}
和
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'customerid' => str_random(30),
]);
}
和 register.blade.php :
<form method="POST" action="/auth/register">
{!! csrf_field() !!}
<div>
<input type="hidden" name="customerid">
Name
<input type="text" name="username" value="{{ old('username') }}">
</div>
<div>
Email
<input type="email" name="email" value="{{ old('email') }}">
</div>
<div>
Password
<input type="password" name="password">
</div>
<div>
Confirm Password
<input type="password" name="password_confirmation">
</div>
<div>
<button type="submit">Register</button>
</div>
</form>
错误的运算符“==”,将其替换为“=>”
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'customerid' => str_random(30),
]);
}
您是否在您的模型中提到了可填写的客户 ID? – Imtiaz Pabel
辛苦了谢谢!
使该字段在您的模型中可填写
protected $fillable = ['username', 'email', 'password', 'customerid'];