Laravel 涉及命名空间

Laravel touches with namespaces

我有一个存在于命名空间中的模型:

namespace Enquiry\Parts;

我正在尝试 "touch" 不同的模型:

protected $touches = array('Enquiry/Enquiry');

但这失败了:

Call to undefined method Illuminate\Database\Query\Builder::Enquiry/Enquiry()

备选方案也失败了:

protected $touches = array('/Enquiry');
protected $touches = array('Enquiry');

我该如何解决这个问题?


根据 Jeroen 的回答,我创建了一个关系并相应地调整了 $touches:

...
protected $touches = array('enquiry');
...
public function enquiry(){
    return $this->belongsTo('Enquiry\Enquiry', 'enquiryId');
}

您必须定义从当前模型到您要接触的模型的 belongsTo 关系。然后,将关系名称(方法名称)放在 $touches 数组中,而不是模型 (class) 名称。

例如:

protected $touches = array('enquiry');

public function enquiry()
{
    return $this->belongsTo('Enquiry/Enquiry');
}