jcadima
9/9/2017 - 5:32 PM

Combine Order by and Paginate in Query

Combine Order by and Paginate in Query

https://laracasts.com/discuss/channels/laravel/combining-paginate-with-orderby?page=1

<?php

public function index()
{
    // $tasks = Task::all() ;  // retrieve all Tasks
    $users =  User::all() ;
    $tasks  = DB::table('tasks')->orderBy('created_at', 'desc')->paginate(10) ;  // Paginate Tasks 
    return view('task.tasks')->with('tasks', $tasks) 
                             ->with('users', $users ) ;
}