在 Laravel 5 中加载具有多重关系的雄辩模型时出错


Error while Eager loading a Eloquent model with multiple relationship in Laravel 5

我的User模型有两个关系

public function group(){
                return $this->belongsTo('App'Group','group_id');
            }
public function profile()
            {
                return $this->hasOne('App'Profile','user_id');
            }

并在控制器中访问它们,例如

 $users = 'App'User::with('group','profile')->get();

但是,检索Profile Model's column give error(在@foreach循环内)

@foreach ($users as $user)
    URL::action('ProfileController@edit',[$user->profile->id])
@foreach ($users as $user)

错误

Trying to get property of non-object 
(View: C:'xampp'htdocs'laravel1'resources'views'user'index.blade.php)

调试:虽然dd($user)给出了相关数据,但为什么会出现错误?

附言 dd($user)输出链路 = http://bit.ly/1IxEpVk

您正在尝试从空配置文件中获取 id。请检查您的结果之一,并查看您的内部关系属性您的配置文件为空

请先检查个人资料是否为空,然后才获取您的字段

祝你好运。