我想在laravel中获取关系中关系对象的对象即
public function skills() {
return $this->hasMany("AppJobSkill", "object_id", "id")->where('object_type','=', 'j');
}
$query->with(['skills' => function ($sql) {
echo "<pre>";
print_r($sql->get()->toArray());
die;
}])
我使用这个方法,但我得到了这个表的所有数据,而不是我定义的这个关系对象。
public function skills() {
$skills = $this->hasMany("AppJobSkill", "object_id", "id")->where('object_type','=', 'j');
//check to make sure its not an empty collection.
if($skills){
//do stuff with $skills
dd($skills);
}
return $skills;
}])