mercredi 31 octobre 2018

Refer to a value just set in array within foreach loop

We've got a foreach loop that one of our console commands, it builds an array to be put in the database after being turned to Json.

In order to get one of the specific values, we'd like to reference two of the OTHER values that have been pulled in the loop

Below is the loop, the 'conversionRate' valus is what we're trying to get, from the result of the 'sales' and 'quotes' queries. I have no idea how to call those while still inside the loop.

 foreach ($users as $user) {
            $todaysCcActionsArray[] = [
                'name' => DB::Table('sw_users')->where('EmailAddress', $user)->value('FirstName'),

                'code' => $user,

                'sales' => Order::where('Status', 'BOOKING')
                ->whereNotIn('Product', ['commercial_insurance', 'home_insurance'])
                ->where('MasterOrderNumber', 0)
                ->whereNull('OriginalOrderNumber')
                ->where('CallCentreID', '!=', $user)
                ->whereDate('OrderDate', '=', date('Y-m-d'))->count(),

                'quotes' => Order::where('Status', 'QUOTE')
                ->whereNotIn('Product', ['commercial_insurance', 'home_insurance'])
                ->where('MasterOrderNumber', 0)
                ->whereNull('OriginalOrderNumber')
                ->where('CallCentreID', '!=', $user)
                ->whereDate('OrderDate', '=', date('Y-m-d'))->count(),

                'conversionRate' => 'sales' / 'quotes' * 100
            ];
        }



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

Aucun commentaire:

Enregistrer un commentaire