public static function preloadAddresses($value, $origin = null, $fieldValues = null)
    {
        if ($value) {
            if ($origin == 'client') {
                $result = collect(Client::where('id', $value)
                                        ->first()
                                        ->addresses
                                        ->all())
                                  ->transform(function ($item) {
                                      return ['label'   => $item['name'],
                                              'display' => $item['name'],
                                              'value'   => $item['id'], ];
                                  })->toArray();
            }

            if ($origin == 'costCenter') {
                $result = collect(CostCenter::where('id', $value)
                                        ->first()
                                        ->addresses
                                        ->all())
                                  ->transform(function ($item) {
                                      return ['label'   => $item['name'],
                                              'display' => $item['name'],
                                              'value'   => $item['id'], ];
                                  })->toArray();
            }

            return ['options' => $result];
        } else {
            return ['label' => null, 'options' => null, 'value' => null];
        }
    }
public static function preloadAddresses($value, $origin = null, $fieldValues = null)
    {
        if ($value) {
            if ($origin == 'client') {
                $result = collect(Client::where('id', $value)
                                        ->first()
                                        ->addresses
                                        ->all())
                                  ->transform(function ($item) {
                                      return ['label'   => $item['name'],
                                              'display' => $item['name'],
                                              'value'   => $item['id'], ];
                                  })->toArray();
            }

            if ($origin == 'costCenter') {
                $result = collect(CostCenter::where('id', $value)
                                        ->first()
                                        ->addresses
                                        ->all())
                                  ->transform(function ($item) {
                                      return ['label'   => $item['name'],
                                              'display' => $item['name'],
                                              'value'   => $item['id'], ];
                                  })->toArray();
            }

            return ['options' => $result];
        } else {
            return ['label' => null, 'options' => null, 'value' => null];
        }
    }
public static function preloadAddresses ( $ value , $ origin = null , $ fieldValues = null ) { if ( $ value ) { if ( $ origin == 'client' ) { $ result = collect ( Client :: where ( 'id' , $ value ) -> first ( ) -> addresses -> all ( ) ) -> transform ( function ( $ item ) { return [ 'label' => $ item [ 'name' ] , 'display' => $ item [ 'name' ] , 'value' => $ item [ 'id' ] , ] ; } ) -> toArray ( ) ; } if ( $ origin == 'costCenter' ) { $ result = collect ( CostCenter :: where ( 'id' , $ value ) -> first ( ) -> addresses -> all ( ) ) -> transform ( function ( $ item ) { return [ 'label' => $ item [ 'name' ] , 'display' => $ item [ 'name' ] , 'value' => $ item [ 'id' ] , ] ; } ) -> toArray ( ) ; } return [ 'options' => $ result ] ; } else { return [ 'label' => null , 'options' => null , 'value' => null ] ; } }
cost center addresses + the client addresses.
cost center addresses + the client addresses .