Skip to content

Instantly share code, notes, and snippets.

@sleeping-owl
Created November 17, 2014 14:02
Show Gist options
  • Save sleeping-owl/2e1d1cef3d820e440b51 to your computer and use it in GitHub Desktop.
Save sleeping-owl/2e1d1cef3d820e440b51 to your computer and use it in GitHub Desktop.
<?php
class Product extends \Eloquent
{
public function category()
{
return $this->belongsTo('Category');
}
public function options()
{
return $this->belongsToMany('ProductOption');
}
}
class ProductOption extends \Eloquent
{
public function products()
{
return $this->belongsToMany('Product');
}
}
class Category extends \Eloquent
{
public function products()
{
return $this->hasMany('Product');
}
}
$products = Product::with('category', 'options')->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment