0

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?

2
  • 1
    BTW, Invoice_detail::whereId(27)->first(); == Invoice_detail::find(27); Mar 4, 2014 at 0:51
  • @JosephSilber A lot cleaner. Thanks!
    – Casey
    Mar 4, 2014 at 1:13

1 Answer 1

2

Yep - your relationship methods should have returns on them:

public function invoiceDetails()
{
    return $this->hasMany('Invoice_detail');
}
1
  • You can't imagine the shame I feel right now. I spent over an hour staring at it, renaming it, changing the camelCasing, trying underscores. This is face palm on an epic level. Thank you.
    – Casey
    Mar 4, 2014 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.