Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting last element of the Collection

guys, I'm trying to get the last element from the data returned to me but the problem is that it is throwing me an error which is

Call to undefined method Illuminate\Database\Query\Builder::last()

Here is my code

$last_saved_snapshot = \EnginePerformanceTestSnapshot::where('engine_performance_test_id', $id)->last();

Please tell me what is it that I'm doing wrong. Thanks

P.S I'm using Laravel 5.0

like image 307
Gardezi Avatar asked Oct 14 '16 11:10

Gardezi


Video Answer


1 Answers

Try something like that:

$last_saved_snapshot = \EnginePerformanceTestSnapshot::where('engine_performance_test_id', $id)
    ->get()
    ->last();
like image 125
Marek Skiba Avatar answered Oct 04 '22 08:10

Marek Skiba