从目录laravel获取所有产品

I have 3 tables:

product
*id
category_id
name
...

category
*id
catalog_id
name
...

catalog
*id
name
...

and 3 models

class Catalog extends Model
{
    public function category()
    {
        return $this->hasMany('App\Category');

    }
}

class Category extends Model
{
    public function product()
    {
        return $this->hasMany('App\Product');

    }

    public function catalog()
    {
        return $this->belongsTo('App\Catalog');
    }
}

class Product extends Model
{
    public function category()
    {
        return $this->belongsTo('App\Category');

    }
}

I'm working with data through repositories

example:

abstract class Repository
{
    protected $model = false;

    public function get($select = '*',$where = false, $take = false)
    {
        $builder = $this->model->select($select);

        if($where)
        {
            $builder->where($where);
        }

        if($take)
        {
            $builder->take($take);
        }

        return $builder->get();
    }
}

class ProductsRepository extends Repository
{

    public function __construct(Product $products)
    {
        $this->model = $products;
    }

    public function getNewProducts()
    {
        return $this->get('*',['is_recommended' => 1],Config::get('settings.recommended_products_count'));
    }

    public function getProductsFromCategory($category_id)
    {
        return $this->get('*',['category_id' => $category_id]);
    }


}

So, the question is: how can I get all products from catalog by it's id? in raw sql it'll look like:

select * from products
     join categories
        on categories.id=products.category_id
     join catalogs
        on catalogs.id=categories.catalog_id
where(catalogs.id=1)

but how can I get them in my situation?

First, define a relation between catalogue and products in Catalog model:

public function products()
{
    return $this->hasManyThrough('App\Product', 'App\Category', 'catalog_id', 'category_id', 'id');
}

Now, you should be able to get all products for given catalog with:

$products = Catalog::with('products')->find($id)->products;

You can find out more about has-many-through relation here: https://laravel.com/docs/5.4/eloquent-relationships#has-many-through