@php use Illuminate\Support\Facades\DB; $Material = DB::table('tmstmmaterial'); $Material->where('xbisactive', 1); if(isset($WhereType) && isset($ValueWhere) && isset($operator)){ $Material->where($WhereType,$operator,$ValueWhere); } $Material = $Material->orderBy('xvmatcode','desc')->get()->toArray(); foreach ($Material as $item){ $item->unit = DB::table('tmstmmat_unit') ->where('xvmatcode','=',$item->xvmatcode) ->join('tmstmunit', 'tmstmmat_unit.xvuntcode', 'tmstmunit.xvuntcode') ->get()->toArray(); } @endphp