Laravel Relationship problems: Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation

StackOverflow https://stackoverflow.com/questions/22160580
  •  
  •  | 
  •   ( words)

Frage

I must be missing something obvious. I've got a Invoice_detail Model:

class Invoice_detail extends Eloquent {

public function products()
{
    $this->belongsTo('Product');

}
}

A Product Model:

class Product extends Eloquent {

public function invoiceDetails()
{
    $this->hasMany('Invoice_detail');
}
}

but when I try to use this:

Route::get('/', function(){

  $detail =  Invoice_detail::whereId(27)->first();

  return $detail->products;
});

I get: Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation

What am I missing here?

War es hilfreich?

Lösung

Yep - your relationship methods should have returns on them:

public function invoiceDetails()
{
    return $this->hasMany('Invoice_detail');
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow