Laravel Eloquent 报错:HasOne::$id Undefined Property
,代码如下:
// Workflow 模型
class Workflow extends Model
{
public function startNode(){
return $this->hasOne(Node::class)->ofMany('sort', 'min');
}
}
//调用报错
$start = $workflow->startNode()->id;
//正确调用方法,去掉方法后面的括号
$start = $workflow->startNode->id;