Reputation: 170
I am struggling with a query! In my SQL Server I put first();
instead of get();
and I get the last result so in LARAVEL 4.2 I get an error. Do you have any advice? Is there a different way to do this? I will give you the code in case you need more information.
Thank you for your time!
$users = DB::table('Home_Students')
->select('home_firstname','home_lastname','LogSt_data','LogSt_date')
->join('Home_LogStudents','Home_LogStudents.LogSt_studid','=','Home_Students.home_id')
->join('LessonUnitSections','LessonUnitSections.leuns_ID','=','Home_LogStudents.LogSt_sectionID')
->join('LessonUnits','LessonUnits.leun_ID','=','LessonUnitSections.leuns_LessonUnitID')
->where('Home_LogStudents.LogSt_action','=',225)
->where('Home_LogStudents.LogSt_data','<>',0)
->where('Home_LogStudents.LogSt_sectionID','=',$id)
->orderBy('LogSt_date','home_firstname')
->get();
Upvotes: 4
Views: 5487
Reputation: 163798
Try to add orderBy desc
to the query, that should solve your problem.
For example, instead of:
->orderBy('LogSt_date','home_firstname')
Use this:
->orderBy('LogSt_date', 'desc')->orderBy('home_firstname', 'desc')
Also, if you do not get error message using get()
, try to use ->take(1)->get()
instead of ->first()
Upvotes: 2