Sometimes we need to use orders to get the data from database like order by date order name order by create extra. In this snippet, we’re using Laravel Eloquent to fetch users from their table and ordering them in descending order by their names thanks to the orderBy()
method. In Laravel the query ordering is always done during the phase operation and it is done in the following way:
$data = DB::table('posts')->where('post_status_for_frontend', 1)->orderBy('updated_at', 'desc')->paginate(4);