我必須錯過一些明顯的東西。我有一個Invoice_detail型號:Laravel Relationship Probelms
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) - >第一();''== :: Invoice_detail找到(27);' –
@JosephSilber很多清潔工。謝謝! – Casey