select data from 3 tables in laravel by using Eloquent ORM <p>I am new to laravel and stuck on getting data using Eloquent ORM.</p> <p>My Scenario is I have 3 tables</p> <ol> <li>user - Contains user info</li> <li>location - Contains Location info</li> <li>location_user - Contains user id , location id , time when the user visited that location.</li> </ol> <p>Now a user can visit a location multiple times and a location can be visited by multiple users.</p> <p>I want to get all location name that a user visited on particular date.</p> <p>But unable to get.</p> <p>Below is the db structure</p> <p>location_user table - id user_id location_id visitedtime</p> <p>location table - id latitude longitude locality </p> <p>user table - id name phone email </p> <p>and In user model I have defined the relation</p> <pre><code>public function locations() { return $this-&gt;belongsToMany('Location')-&gt;withPivot('visitedtime'); } </code></pre> <p>when i use this function in controller then i get all the locations visited by that user</p> <pre><code>User::find(2)-&gt;locations()-&gt;select('locations.locality',locations.id')-&gt;get() </code></pre> <p>How can put condition on visitedtime on the above function</p>