Answer the question
In order to leave comments, you need to log in
Is it possible to sort in reverse order on paginate() without using the DB:: facade?
Hello.
I need to display records from the database in reverse order and with pagination.
The only method I've found so far is something like:
$tickets = DB::table('ticket')->orderBy('id', 'desc')->paginate(10);
Answer the question
In order to leave comments, you need to log in
You can use the Eloquent model rather than the query builder. (through facade)
You can also inject a dependency through the constructor:
class TicketController extends Controller
{
protected $ticket;
public function __construct(Ticket $ticket)
{
$this->ticket = $ticket;
}
// для примера метод index
public function index()
{
$tickets = $this->ticket->orderBy('id', 'desc')->paginate(10);
return view('tickets.index', [
'tickets' => $tickets,
]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question