$query = Post::join('categories', 'categories.id','=','products.category_id');
$query = $query->select('categories.name as cat_name','products.*');
$query = $query->orderBy('cat_name','asc');
$records = $query->get();
User::with(['withdrawals' => function($query) {
$query->select('id', 'name')->orderBy('created_at')->with(['withdrawalitems' => function($query) {
$query->select('id', 'name')->orderByDesc('created_at')
}])
}])->get();