【发布时间】:2018-12-15 16:22:21
【问题描述】:
我一定遗漏了一些明显的东西。我有一个 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
我在这里错过了什么?
【问题讨论】:
-
顺便说一句,
Invoice_detail::whereId(27)->first();==Invoice_detail::find(27); -
@JosephSilber 干净多了。谢谢!