我必须遗漏一些明显的东西。我有一个Invoice_detail模型:
class Invoice_detail extends Eloquent {
public function products()
{
$this->belongsTo('Product');
}
}
产品型号:
class Product extends Eloquent {
public function invoiceDetails()
{
$this->hasMany('Invoice_detail');
}
}
但是当我尝试使用它时:
Route::get('/', function(){
$detail = Invoice_detail::whereId(27)->first();
return $detail->products;
});
我得到:Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
我在这里缺少什么?
答案 0 :(得分:2)
是的 - 你的关系方法应该有回报:
public function invoiceDetails()
{
return $this->hasMany('Invoice_detail');
}