我一直工作在一个应用程序的某个时候现在..突然我得到这个奇怪的错误。显示的数据与我在数据库中的数据不同。 这就是我在我的数据库”Laravel显示不同的数据从数据库数据
id - 1
name - Jon Doe
email - [email protected]
status - jobseeker
created_at - 2017-06-20 21:02:47
updated_at - 2017-06-20 21:02:47
但是,当我显示的数据,这是我得到
{"id":1,"name":"Jon Doe","email":"[email protected]","status":"employer","created_at":"2017-06-20 21:02:47","updated_at":"2017-06-20 21:02:47","employer":null}
而我使用的刀片“{{验证::用户()}}“以登录后显示用户信息
我认为它与vardump数据时的”属性“和”原始“有关。
我不知道在哪里的变化正在发生。我正在使用Laravel默认身份验证来创建用户。
这是我创建的用户表单..
<form role="form" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label>Name</label>
<input type="text" class="form-control" name='name' placeholder="Your Name" required>
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label>Email</label>
<input type="email" class="form-control" name='email' placeholder="Your Email" required>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label>Password</label>
<input type="password" class="form-control" name="password" placeholder="Your Password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
<div class="form-group">
<label>Re-type Password</label>
<input type="password" class="form-control" name="password_confirmation" placeholder="Re-type Your Password" required>
</div>
<div class="form-group">
<label >Register As</label>
<select class="form-control" required name="status">
<option value="">--select--</option>
<option value="jobseeker">Job Seeker </option>
<option value="employer"> Employer </option>
</select>
</div>
<div class="white-space-10"></div>
<div class="form-group no-margin">
<button class="btn btn-theme btn-lg btn-t-primary btn-block">Register</button>
</div>
</form>
这是我的用户模型
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password','status'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function employer(){
return $this->hasOne('App\Employer');
}
public function jobseeker(){
return $this->hasOne('App\Jobseeker','user_id');
}
}
这是编辑我这样做的“状态”可以被添加到用户表因为它没有使用默认的laravel认证。
我编辑的registerController的创建功能,这
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'status' => $data['status'],
'password' => bcrypt($data['password']),
]);
}
,这是我的用户迁移表
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('status')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
希望这有助于
我知道你认为我们在#1,是魔术师告诉你什么是错的不看任何代码的,但说实话,我们只是凡人人类。请在您从数据库获取数据以及如何处理数据的地方发布相关代码。至于最后两个字段,Laravel默认情况下将其添加 – Silencer310
抱歉..我加入再次编辑更多信息 –
..显示的数据是不是在数据库中 –