Q:

How I can make the same SQL query whith the halp of Eloqument ORM methods and models

I have followng database:

And database diagramm is on next picture. Simply speaking, Users have many shops, Shops have many products etc. 

In need to select all products from all shops of particular user. In my Controller it's look like so:

But it's does't work ( 
Instade of this I try to write direct SQL 
I just need to make following request by Eloqument methods
SELECT * FROM tmp.products
WHERE tmp.products.shop_id IN
(SELECT id FROM shops where user_id = 1);

with dynamics parametrs of course.

A:

You could get all products by using whereHas filter like 
$products = Product::whereHas('shop.user', function ($query) use($request) {
    $query->where('id', '=', $request->user()->id);
})->get();

I assume you have defined proper mappings in your models like 
class Product extends Model {

    public function shop() {
        return $this->belongsTo('Shop', 'shop_id');
    }
}

class Shop extends Model {
    public function user() {
        return $this->belongsTo('User', 'user_id');
    }
    public function products() {
        return $this->hasMany('Product', 'shop_id');
    }
}

class User extends Model {

    public function shops() {
        return $this->hasMany('Shop', 'user_id');
    }
}

