Q:

Laravel 5.2 Find a Model Based on a Many-to-Many relationship

I'm having an issue with writing an eloquent query for a search function in my project. 
Here are my database tables/models:
artist
| id | name         |
---------------------
| 1  | Van Gogh     |
| 2  | Michelangelo |

art
| id | title        |
---------------------
| 1  | David        |
| 2  | Starry Night |

art_artist
| id | art_id | artist_id |
---------------------------
| 1  | 1      | 2         |
| 2  | 2      | 1         |

style
| id | title        |
---------------------
| 1  | Sculpture    |
| 2  | Painting     |

art_style
| id | art_id | style_id |
--------------------------
| 1  | 1      | 1        |
| 2  | 2      | 2        |

One artist hasMany art pieces, one art piece hasMany styles, and also hasMany artists.  I have verified that the relationships work correctly.  I also have a simple form that returns ids as a GET request with the variables artist and style. 
So, I want to do two things in my function: First, check if the variables in the request are set (I can already do this).  Then, USE ELOQUENT to query the art model based on the results of the form. 
Here's an example: A user searches for a Sculpture by Michelangelo.  The function queries the art database for any piece that is a sculpture by michelangelo and returns it as an art model. 
The trouble is, I have absolutely no idea how to query the database based on the id of a related model.  Any ideas? 

A:

I finally figured out how to do the query.  First, I have to tell Eloquent I want to retrieve the artist model along with the art, THEN I can use whereHas:
$art = Art::with('artists')->whereHas('artists',function( $query ){
    $query->where('artists.id',1);
})->get();

