Support the ongoing development of Laravel.io →
Database Eloquent

Hi there.

Here is my code:

$personelList = App::make('MedPersonel')
    ->with( array('servicePrices' => function($query){
            $query->selectRaw('ARRAY_AGG(med_service_id) AS med_service_id, ARRAY_AGG(med_service_price) AS med_service_price');
            $query->groupBy('med_facility_id');
  }))
 ->with('specialization')
 ->limit(1)
 ->get()->toArray()

;

Problem is that $personelList[0]['service_prices'] is an empty array. But when i do it this way:

  $personelList = App::make('MedPersonel')
      ->with( array('servicePrices' => function($query){  }))
      ->with('specialization')
      ->limit(1)
      ->get()->toArray()
 ;

$personelList[0]['service_prices'] - contains elements.

Why? I check db log and there is a proper query to get service prices from database in both cases.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

halfik halfik Joined 18 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.