mercredi 23 août 2017

How to perform a calculation on a row basis and SUM on laravel

I have a situtaion where I have data in two columns in a table, which need to be multiplied on a row basis. Then each value from the multiplication has to be added to provide a net result

I tried this but it does not work

  public function getCampaignStats($item)
    {
        $query = CampaignStats::where('item',$item);
        foreach($query as $q) {
            $q->p_c;
            $q->caa;
            dd($q->p_c);
        }
        return $query;
    }

I get this exception when i try to do this

Object of class Illuminate\Database\Eloquent\Builder could not be converted to string

Is there a better way to do this foreach loop in laravel



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

Aucun commentaire:

Enregistrer un commentaire