I have 3 tables: Users, Tasks and Records.
Users have many tasks Tasks have many records.
I'm trying to select all records in a given date for a specific user. (these 2 tables "join" indirectly through the tasks table)
The two separate selects are these:
$records = Record::where('date','=', $date ) $tasks = Task::where('user_id', '=', $user_id)
I'm trying something like this:
$lastRecord = $user->tasks->records->get('date');
Obviously doesn't work, but kinda explains what I'm trying to retrieve.
The example sql query would be something like this:
select * from records join tasks where records.task_id == tasks.id join users where tasks.user_id == users.id where records.date == '2014-07-13'
Can someone help me out? I'm new to eloquent.
Have a look at this relationship
http://laravel.com/docs/eloquent#has-many-through
I believe it is exactly what you need
Wow, so simple and effective, Laravel is awesome Thanks TorchSK
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community