Php 有说服力的不链接表
我有三张桌子。但是拉威尔没能把桌子联系起来,我觉得我错过了一件很小的事情,但我似乎找不到 控制器Php 有说服力的不链接表,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,我有三张桌子。但是拉威尔没能把桌子联系起来,我觉得我错过了一件很小的事情,但我似乎找不到 控制器 $data = Item::all(); $clipper = $data->first(); dd($clipper->attributes()); 项目 protected $table = 'item'; protected $primaryKey = 'item_id'; public $timestamps = false; public function attribut
$data = Item::all();
$clipper = $data->first();
dd($clipper->attributes());
项目
protected $table = 'item';
protected $primaryKey = 'item_id';
public $timestamps = false;
public function attributes() {
return $this->hasMany('App\Attributes', 'item_id');
}
a广播
protected $table = 'attributes';
protected $primaryKey = 'attr_id';
public $timestamps = false;
public function name() {
return $this->hasOne('App\Attributesname', 'name_id');
}
属性名称
protected $table = 'item_attributes';
protected $primaryKey = 'item_attr_id';
public $timestamps = false;
尽职调查结果
数据库设计
Laravel链接关系良好,请查看您输出的父模型是项,相关模型是项,尝试此操作以查看相关数据(非关系):
您不知道这是否是因为您尚未查询或加载关系。。。关系方法返回关系类型对象(基本上是查询生成器),它们不返回关系的结果
$data = Item::all();
$clipper = $data->first();
dd($clipper->attributes);