How to bring only the latest records with Laravel 5.2

2

I need to return the last 10 records for a view ..

return view('home.home', [
    'data' => $this->sale->get(), //aqui eu quero pegar os 10 últimos
    'nav' => 'dashboard'
]);

Is there any Eloquent method that does this?

    
asked by anonymous 20.10.2016 / 15:59

1 answer

4

Has the method is take , but it's important that you do the sorting ( orderBy ), so you do not have surprises in the result.

  

$this->sale->orderBy('id','desc')->take(10)->get()

return view('home.home', [
    'data' => $this->sale->orderBy('id','desc')->take(10)->get(), 
    'nav' => 'dashboard'
]);
    
20.10.2016 / 16:01