Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel:hasOne返回空数组_Php_Laravel 5_Relationship - Fatal编程技术网

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) { }