Support the ongoing development of Laravel.io →
Eloquent Views
Last updated 1 year ago.
0

I would do something like this:

$studentAttendance = App::make('StudentAttendance');
$lastRecord = $studentAttendance->order_by('created_at', 'desc')->first()

Hope that helps!

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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/

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

tpbsv77 tpbsv77 Joined 12 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.