Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
Laravel 表之间的关系出错_Laravel_Laravel 5_Eloquent_Laravel 5.3 - Fatal编程技术网

Laravel 表之间的关系出错

Laravel 表之间的关系出错,laravel,laravel-5,eloquent,laravel-5.3,Laravel,Laravel 5,Eloquent,Laravel 5.3,我有一个错误,当我试图获得一些数据之间的两个表使用雄辩。 给我的错误是: Error: Trying to get property of non-object (View: 这是我的应用程序信息 DB: survey: - id; - template_id; - title; templates: - id; - name; - internal_name; SurveyModel: public function theme(){ return $this-&

我有一个错误,当我试图获得一些数据之间的两个表使用雄辩。 给我的错误是:

Error:
Trying to get property of non-object (View: 
这是我的应用程序信息

DB:
survey:
- id;
- template_id;
- title;


templates:
- id;
- name;
- internal_name;

SurveyModel:
 public function theme(){

        return $this->hasOne(Template::class, 'template_id','id');
}


View:

@foreach($surveys->reverse() as $survey)

        <tr>
        <td>{{$survey->template_id->theme}}</td>

</tr>
@endforeach
DB:
调查:
-身份证;
-模板标识;
-头衔;
模板:
-身份证;
-姓名;
-内部名称;
调查模型:
公共职能主题(){
返回$this->hasOne(Template::class,'Template_id','id');
}
视图:
@foreach($surveys->reverse()作为$survey)
{{$survey->template_id->theme}
@endforeach

您应该直接使用它们:

<td>{{$survey->theme}}</td>
希望这有帮助

<td>{{$survey->theme->name}}</td>