Laravel 5.2 with pagination

Asked

Viewed 624 times

4

I have the following function inside the controller

public function home()
{
    $igrejas = Igreja::paginate(3);
    $igrejas->setPath('igrejas');
    return view('admin/igrejas/home')->with('igrejas', $igrejas);
}

I need it to be returned beyond pagination, by order of creation, that the last records appear on the first page. As it stands the system brings in the last pages the last records, I need the reverse.

  • If you have a data_register column with default now() you can sort by this column using the Miguel method below, but by changing the column value.

  • Exactly @Peterparker, this will even give the same if there is a column with auto-increment (as is the case with the id by convention). It is automatically ordered by creation

1 answer

4


A small change:

...
Igreja::orderBy('id', 'DESC')->paginate(3);
...

Note that I am assuming that there is a column id auto-increment in this table, if there is no order by the column you would like

  • It worked with this amendment, thank you !

  • You’re welcome @Danilotiagothaisantos . I’m glad you decided

Browser other questions tagged

You are not signed in. Login or sign up in order to post.