【发布时间】:2018-10-15 12:05:00
【问题描述】:
我正在尝试从数据透视表中获取数据,但它显示“尝试获取非对象的属性‘标签’”。即使表中有一些数据,控制器中的 find(1) 也不会返回任何内容。
我的模型:
class Videos extends Model
{
protected $table = 'videos';
function tags(){
return $this->belongsToMany('App\Models\Videos\Tags','tag_video','video_id','tag_id');
}
class Tags extends Model
{
function videos(){
return $this->belongsToMany('App\Models\Videos\Videos','tag_video', 'tag_id','video_id');
}
}
我的控制器:
public function fetch(){
$videos_from_supercategories =
$videos_with_tags = Videos::find(1);
$tags = $videos_with_tags->tags->first();
$data['tags']=$tags;
return $data;
}
有人可以帮忙吗?
【问题讨论】: