I would do something like this:
$studentAttendance = App::make('StudentAttendance');
$lastRecord = $studentAttendance->order_by('created_at', 'desc')->first()
Hope that helps!
I would think that it would be a pretty common thing to do, I am just not seeing how laravel handles it: What I need to do is something like this:
For each record in the attendance table, I record the date, student_id
Then in a students_attendance table, I record attendance_id, time_in, time_out
So if there are say 3 records from the students_atandance table for one attendance ID, then I only want to show the last record as that will be the most up to date.
Yeah, the example I showed is how you would do it. You create two models, Attendance and StudentAttendance. You define their relationship in the models as well. You're then able to chain calls. For example
$studentAttendance = App::make('StudentAttendance'); // Getting an instance of the StudentAttendance model
$allRecords = $studentAttendance->attendances()->get(); // Get all records for that studentAttendance
If you want only the most recent, you would add an order_by() to the chain like in the example above and use the ->first() method instead of ->get(). Hopefully this clears it up but if not, try looking at the links below, some good resources.
http://laravel.com/docs/eloquent http://cheats.jesse-obrien.ca/
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community