我在My laravel应用程序中使用Auth:命令注册表单。 并且我已经为register.blade.php文件添加了新的nic输入框,如register.blade.php
<div class="form-group{{ $errors->has('nic') ? ' has-error' : '' }}"> <label for="nic" class="col-md-4 control-label">NIC</label> <div class="col-md-6"> <input id="nic" type="text" class="form-control" name="nic"> @if ($errors->has('nic')) <span class="help-block"> <strong>{{ $errors->first('nic') }}</strong> </span> @endif </div> </div>和我的AuthController是这样的,
protected function validator(array $data) { return Validator::make($data, [ 'username' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6|confirmed', 'nic' => 'required|min:10', ]); } protected function create(array $data) { return User::create([ 'username' => $data['username'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'nic' => $data['nic'], ]); }并且我在Users表中也有新的专栏。 但是当我点击注册按钮时,其他数据值很好地保存在用户表中,但是密码栏没有保存好的值。 如何解决这个问题?
I am using Auth: command register form in My laravel application. and I have add new nic input box to register.blade.php file as this, register.blade.php
<div class="form-group{{ $errors->has('nic') ? ' has-error' : '' }}"> <label for="nic" class="col-md-4 control-label">NIC</label> <div class="col-md-6"> <input id="nic" type="text" class="form-control" name="nic"> @if ($errors->has('nic')) <span class="help-block"> <strong>{{ $errors->first('nic') }}</strong> </span> @endif </div> </div>and MY AuthController is like this,
protected function validator(array $data) { return Validator::make($data, [ 'username' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6|confirmed', 'nic' => 'required|min:10', ]); } protected function create(array $data) { return User::create([ 'username' => $data['username'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'nic' => $data['nic'], ]); }and I have new column as nic in Users table as well. but when I click register button other data values saving well in users table but nic column not saving nic values. how can solve this problem?
最满意答案
检查您的用户模型是否在$fillable数组中添加了nic,因为您执行的是批量分配
<?php namespace App; use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Backpack\Base\app\Notifications\ResetPasswordNotification as ResetPasswordNotification; class User extends Authenticatable { use Notifiable; protected $fillable = ['username', 'email', 'password', 'nic']; }Check in your User model if nic is added in $fillable array because you do a mass assignement
<?php namespace App; use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Backpack\Base\app\Notifications\ResetPasswordNotification as ResetPasswordNotification; class User extends Authenticatable { use Notifiable; protected $fillable = ['username', 'email', 'password', 'nic']; }更多推荐
发布评论