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