Php Laravel:hasOne返回空数组
我自己也找不到解决这个问题的方法,所以是时候向有知识的人寻求帮助了(再一次…) 上下文 用户表Php Laravel:hasOne返回空数组,php,laravel-5,relationship,Php,Laravel 5,Relationship,我自己也找不到解决这个问题的方法,所以是时候向有知识的人寻求帮助了(再一次…) 上下文 用户表 public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name', 40); $table->string('email')->unique
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 40);
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function up()
{
Schema::create('userprofiles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('avatar');
$table->text('description');
$table->string('social');
$table->string('video');
$table->timestamps();
});
}
用户档案表
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 40);
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function up()
{
Schema::create('userprofiles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('avatar');
$table->text('description');
$table->string('social');
$table->string('video');
$table->timestamps();
});
}
**播种机**
public function run()
{
$user = App\User::create([
'name' => 'Unicorn',
'email' => 'unicorn@gmail.com',
'password' => bcrypt('password'),
'superadmin' => 1,
]);
App\Userprofile::create([
'user_id' => $user->id,
'avatar' => '/uploads/avatars/avatar.jpg',
'description' => 'You just keep learning',
'social' => 'facebook.com',
'video' => 'youtube.com',
]);
}
用户配置文件模型(在App/Userprofile.php中)
结果本身
NULL array(0) { }
如果我只查询App\User::find(1)或App\Userprofile::find(1)
,它工作得非常好。但这种关系并非如此。我曾多次尝试修改代码,但都没有成功,我甚至添加了一个外键,而没有外键它应该可以工作(如果我没有错的话)
谢谢你的帮助
NULL array(0) { }