Answers for "using where condition on groupby laravel"

PHP
0

laravel group by with where clause

$groupedSalesCampaign = Order::with('Campaign')
            ->where('isapproved','=','Y')
            ->groupBy('campaign_id')
            ->orderBy(DB::raw('COUNT(id)','desc'))
            ->get(array(DB::raw('COUNT(id) as totalsales'),'campaign_id'));
Posted by: Guest on September-10-2020
0

group where conditions in laravel

<?php

$results = DB::table('table')
             ->where(function($query) use ($starttime,$endtime){
                 $query->where('starttime', '<=', $starttime);
                 $query->where('endtime', '>=', $endtime);
             })
             ->orWhere(function($query) use ($otherStarttime,$otherEndtime){
                 $query->where('starttime', '<=', $otherStarttime);
                 $query->where('endtime', '>=', $otherEndtime);
             })
             ->orWhere(function($query) use ($anotherStarttime,$anotherEndtime){
                 $query->where('starttime', '>=', $anotherStarttime);
                 $query->where('endtime', '<=', $anotherEndtime);
             })
             ->get();
Posted by: Guest on June-20-2021

Code answers related to "using where condition on groupby laravel"

Browse Popular Code Answers by Language