mardi 29 août 2017

Laravel Orderby not working inside Eloquent whereHas relationship?

Please have look on below code.

 $serviceNew = CompletedService::selectRaw('gallons_collected as total,account_id,id,service_provider_id,service_id,service_date')
            ->where("service_id", '1')->where('service_provider_id', $service_privider_id)->whereMonth('service_date', $month)->whereYear('service_date', $year)
            ->with('account')
            ->whereHas('account', function($qs) {
                $qs->orderBy('restaurant_name', 'DESC');
            })
            ->get();

I have multiple records in "CompletedService" and there is one parent id account_id which in account table. and i made with on account.

Already ASC and DESC tried.

Try to order by in whereHas but it's not affect on any records. Below is model relationship.

 public function account() {
    return $this->hasOne('App\Account', 'id', 'account_id');
}

i don't need to orderby in model because i used this relation in multiple time and need only order by in this single query.

Output enter image description here

Every help will be appreciated. Thanks in advance.!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2vAJcnW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire