I want to get all images that belong to a specific gallery. These images have to be selected from Image class. 

this is relationship, inside Image class:

```
public function galleries()
{
    return $this->belongsToMany(Gallery::class, 'gallery_image');
}

```

and inside Gallery:

```
public function images()
{
    return $this->belongsToMany(Image::class, 'gallery_image', 'gallery_id', 'image_id')->withPivot('order');
}

```

I have tried this: 

```
$images = Image::with(array(
    'galleries' => function ($query) use($search)
    {
        $query->where('slug', $search);
    }->paginate()

```

but it still returns all images back even when I send it specific gallery.

Can anyone help me with this query?

It must be done with Image:: and not Gallery:: I must select images through image class and not Gallery class because of a specific way I am doing this. So I need help with above query and not a suggestion to go with Gallery::some\_query\_here