lundi 12 novembre 2018

how to perform a sum with laravel in an eloquent relationship

I have a detail table where there is a relationship with the product table, in the detail table I have a product_id field.

I try to multiply the quantity that appears in the detail table and the price that appears in the product table, used DB ::raw but I get a column error not found.

QueryScope in Detalle Model

 $query->with(['product' => function ($query) {
            $query->select('id', 'name', 'price');
        }])
        ->select('*', DB::raw('SUM(count*products.price) as fullcount'))
        ->groupBy('product_id');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire