3
\$\begingroup\$

This method shows the list of manufacturers' offered products based on the slug and sidebar filters.

Most of the time I have to write the same query with only some changes: you can say I am repeating myself. I want my code more readable and short. How can i refactor and reduce the lines of code?

public function colabrativetwo(Request $request, $slug = 0, $division_id = 0, $section_id = 0, $manufacturer_id = 0, $list="")
{
        $cookieId = $this->setInitialCookie($request);
        if (!empty($cookieId))
            $cookieExists = true;

        $manufacturerArr = array();
        $prodFeatured = array();
            $geting=DB::table('product_category')->select('name')->get();

            $filterArray=array();
            foreach( $geting as $get){
                $localarray=array();
                $localarray['name']=$get->name;
                 $filterArray[]=$localarray;
            }


        if ($slug !== 0 || $division_id != 0 || $section_id != 0 || $manufacturer_id != 0) {

            $where = array();
            $slug_colum = array();
            if ($slug !== 0 && $slug != '') {
                if ($slug == 'low-emitting-material-prerequisite') {

                    $slug_colum[] = 'products.low_emitting_material_prerequisite_expiry_date';
                    $slug_colum[] = 'products.low_emitting_material_prerequisite_file';
                }
                elseif ($slug == 'low-emitting-material-credit')
                {
                    $slug_colum[] = 'products.low_emitting_material_credit_expiry_date';
                    $slug_colum[] = 'products.low_emitting_material_credit_file';
                }

                /*else{
                    $slug_colum[]='products.low_emitting_material_prerequisite_expiry_date';
//                    $slug_colum[] = 'products.low_emitting_material_prerequisite_file';

                }*/

            }

            if ($division_id != 0) {
                $where['products.division_id'] = $division_id;
            }

            if ($section_id != 0) {
                $where['products.section_id'] = $section_id;
            }

            if ($manufacturer_id != 0) {
                $where['manufacturers.id'] = $manufacturer_id;
            }

            if (isset($slug_colum[1])) {

                $productsFeatured = Product::select('products.id','products.low_emitting_material_prerequisite_file',
                'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 'products.name', 'products.logo', 'products.division_id', 'products.section_id', 'products.manufacturer_id', 'divisions.name as division_name', 'divisions.code as division_code', 'sections.name as section_name', 'sections.code')
                        ->where($where)
                        ->whereIn('products.status', ['active'])
                        ->where(function ($query) use ($slug_colum) {
                            if($slug_colum[0] = 'products.low_emitting_material_prerequisite_expiry_date') {
                                $query->where($slug_colum[1], '!=', '');
                            } else {
                                $query->where($slug_colum[0], '>=', date('Y-m-d'))
                                ->where($slug_colum[1], '!=', '');
                            }
                        })
                        ->where('users.user_type', 'manufacturer_paid')
                        ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                        ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                        ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                        ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                        ->join('users', 'manufacturers.user_id', '=', 'users.id')
                        ->orderBy('divisions.code', 'asc')
                        ->orderBy('sections.code', 'asc')
                        ->groupBy('products.id')
                        ->get();


                $divisionsFeatured = Product::select('divisions.id', 'divisions.name as name', 'divisions.code as division_code', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                        ->where($where)
                        ->whereIn('products.status', ['active'])
                        ->where(function ($query) use ($slug_colum) {
                            if($slug_colum[0] = 'products.low_emitting_material_prerequisite_expiry_date') {
                                $query->where($slug_colum[1], '!=', '');
                            } else {
                                $query->where($slug_colum[0], '>=', date('Y-m-d'))
                                ->where($slug_colum[1], '!=', '');
                            }
                        })
                        ->where('users.user_type', 'manufacturer_paid')
                        ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                        ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                        ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                        ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                        ->join('users', 'manufacturers.user_id', '=', 'users.id')
                        ->groupBy('divisions.id')
                        ->get();

                $sectionsFeatured = Product::select('sections.id', 'sections.name as name', 'sections.code', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                        ->where($where)
                        ->whereIn('products.status', ['active'])
                        ->where(function ($query) use ($slug_colum) {
                            if($slug_colum[0] = 'products.low_emitting_material_prerequisite_expiry_date') {
                                $query->where($slug_colum[1], '!=', '');
                            } else {
                                $query->where($slug_colum[0], '>=', date('Y-m-d'))
                                ->where($slug_colum[1], '!=', '');
                            }
                        })
                        ->where('users.user_type', 'manufacturer_paid')
                        ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                        ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                        ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                        ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                        ->join('users', 'manufacturers.user_id', '=', 'users.id')
                        ->orderBy('sections.code', 'asc')
                        ->groupBy('sections.id')
                        ->get();

                $manufacturersFeatured = Product::select('manufacturers.id AS id', 'manufacturers.name AS name', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                        ->where($where)
                        ->whereIn('products.status', ['active'])
                        ->where(function ($query) use ($slug_colum) {
                            if($slug_colum[0] = 'products.low_emitting_material_prerequisite_expiry_date') {
                                $query->where($slug_colum[1], '!=', '');
                            } else {
                                $query->where($slug_colum[0], '>=', date('Y-m-d'))
                                ->where($slug_colum[1], '!=', '');
                            }
                        })
                        ->where('users.user_type', 'manufacturer_paid')
                        ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                        ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                        ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                        ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                        ->join('users', 'manufacturers.user_id', '=', 'users.id')
                        ->orderBy('name', 'asc')
                        ->groupBy('manufacturers.id')
                        // ->limit(3)
                        ->get();
            } else {

                // dd($productsFeatured);
                $productsFeatured = Product::select('products.id','products.low_emitting_material_prerequisite_file',
                'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 'products.name', 'products.logo', 'products.division_id', 'products.section_id', 'products.manufacturer_id', 'divisions.name as division_name', 'divisions.code as division_code', 'sections.name as section_name', 'sections.code')
                        ->where($where)
                        ->whereIn('products.status', ['active'])
                        ->where('users.user_type', 'manufacturer_paid')
                        ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                        ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                        ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                        ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                        ->join('users', 'manufacturers.user_id', '=', 'users.id')
                        ->orderBy('divisions.code', 'asc')
                        ->orderBy('sections.code', 'asc')
                        ->groupBy('products.id')
                        ->get();

                $divisionsFeatured = Product::select('divisions.id', 'divisions.name as name', 'divisions.code as division_code', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                        ->where($where)
                        ->whereIn('products.status', ['active'])
                        ->where('users.user_type', 'manufacturer_paid')
                        ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                        ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                        ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                        ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                        ->join('users', 'manufacturers.user_id', '=', 'users.id')
                        ->groupBy('divisions.id')
                        // ->limit(3)
                        ->get();

                $sectionsFeatured = Product::select('sections.id', 'sections.name as name', 'sections.code', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                        ->where($where)
                        ->whereIn('products.status', ['active'])
                        ->where('users.user_type', 'manufacturer_paid')
                        ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                        ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                        ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                        ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                        ->join('users', 'manufacturers.user_id', '=', 'users.id')
                        ->orderBy('sections.code', 'asc')
                        ->groupBy('sections.id')
                        // ->limit(3)
                        ->get();

                $manufacturersFeatured = Product::select('manufacturers.id AS id', 'manufacturers.name AS name', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                        ->where($where)
                        ->whereIn('products.status', ['active'])
                        ->where('users.user_type', 'manufacturer_paid')
                        ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                        ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                        ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                        ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                        ->join('users', 'manufacturers.user_id', '=', 'users.id')
                        ->orderBy('name', 'asc')
                        ->groupBy('manufacturers.id')
                        // ->limit(2)
                        ->get();
            }
        } else {
            // dd('oan di siri');

            $productsFeatured = Product::select('products.id', 'products.name','products.low_emitting_material_prerequisite_file',
            'manufacturers.phone','manufacturers.address','manufacturers.linkedin_url','manufacturers.city', 'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 'products.logo', 'products.division_id', 'products.section_id', 'products.manufacturer_id', 'divisions.name as division_name', 'divisions.code as division_code', 'sections.name as section_name', 'sections.code')
                    ->whereIn('products.status', ['active'])
                    ->where(function ($query) {
                        $query->where('products.low_emitting_material_prerequisite_file', '!=', '');
                    })
                    ->where('users.user_type', 'manufacturer_paid')
                    ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                    ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                    ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                    ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                    ->join('users', 'manufacturers.user_id', '=', 'users.id')
                    ->orderBy('divisions.code', 'asc')
                    ->orderBy('sections.code', 'asc')
                    ->groupBy('products.id');
                    // ->limit(3)
                    // ->get()

                    if($request->ajax() && $request->manufacturer){

                        $productsFeatured->whereIn('products.manufacturer_id', $request->manufacturer);
                        $productsFeatured = $productsFeatured->get();                     

                    } else{
                        $productsFeatured = $productsFeatured->get();
                    }



// dd($productsFeatured);
            $divisionsFeatured = Product::select('divisions.id', 'divisions.name as name', 'divisions.code as division_code', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                    ->whereIn('products.status', ['active'])
                    ->where(function ($query) {
                        $query->where('products.low_emitting_material_prerequisite_file', '!=', '');
                    })
                    ->where('users.user_type', 'manufacturer_paid')
                    ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                    ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                    ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                    ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                    ->join('users', 'manufacturers.user_id', '=', 'users.id')
                    ->groupBy('divisions.id');
                    // ->get();
                    if($request->ajax() && $request->manufacturer){

                        $divisionsFeatured->whereIn('products.manufacturer_id', $request->manufacturer);
                        $divisionsFeatured = $divisionsFeatured->get();

                    } else{
                        $divisionsFeatured = $divisionsFeatured->get();
                    }



            $sectionsFeatured = Product::select('sections.id', 'sections.name as name', 'sections.code', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                    ->whereIn('products.status', ['active'])
                    ->where(function ($query) {
                        $query->where('products.low_emitting_material_prerequisite_file', '!=', '');
                    })
                    ->where('users.user_type', 'manufacturer_paid')
                    ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                    ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                    ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                    ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                    ->join('users', 'manufacturers.user_id', '=', 'users.id')
                    ->orderBy('sections.code', 'asc')
                    ->groupBy('sections.id');
                    // ->get();
                    if($request->ajax() && $request->manufacturer){

                        $sectionsFeatured->whereIn('products.manufacturer_id', $request->manufacturer);
                        $sectionsFeatured = $sectionsFeatured->get();

                    } else{
                        $sectionsFeatured = $sectionsFeatured->get();
                    }

            $manufacturersFeatured = Product::select('manufacturers.id AS id', 'manufacturers.id AS id',
            'manufacturers.name', 'manufacturers.address',
             'manufacturers.city', 'manufacturers.state', 'manufacturers.state',
             'manufacturers.phone', DB::raw('COUNT(DISTINCT products.id) as products_count'))
                    ->whereIn('products.status', ['active'])
                    ->where(function ($query) {
                        $query->where('products.low_emitting_material_prerequisite_file', '!=', '');
                    })
                    ->where('users.user_type', 'manufacturer_paid')
                    ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                    ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                    ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                    ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                    ->join('users', 'manufacturers.user_id', '=', 'users.id')
                    ->orderBy('name', 'asc')
                    ->groupBy('manufacturers.id');
                    // ->limit(3)
                    // ->get();
                    if($request->ajax() && $request->manufacturer){

                        $manufacturersFeatured->whereIn('products.manufacturer_id', $request->manufacturer);
                        $manufacturersFeatured = $manufacturersFeatured->get();

                    } else{
                        $manufacturersFeatured = $manufacturersFeatured->get();
                    }
        }
            // dd($productsFeatured );
        foreach ($productsFeatured as $productFeatured) {

            $recSecFeatured['fav_yes'] = '';
            $recSecFeatured['id'] = $productFeatured->id;
            $recSecFeatured['name'] = $productFeatured->name;
            $recSecFeatured['logo'] = $productFeatured->logo;
            $recSecFeatured['div_id'] = $productFeatured->division_id;
            $recSecFeatured['division_name'] = $productFeatured->division_name;
            $recSecFeatured['division_code'] = $productFeatured->division_code;
            $recSecFeatured['low_emitting_material_prerequisite_file'] = $productFeatured->low_emitting_material_prerequisite_file;
            $recSecFeatured['specs_file'] = $productFeatured->specs_file;
            $recSecFeatured['specs_file_url'] = $productFeatured->specs_file_url;


            $mfg = Manufacturer::where('id', $productFeatured->manufacturer_id)->first();


            // Manufacturere information
            $mfgArr = array();
            $mfgArr['id'] = $mfg['id'];
            $mfgArr['name'] = $mfg['name'];
            $mfgArr['logo'] = $mfg['logo'];
            $mfgArr['address'] = $mfg['address'];
            $mfgArr['city'] = $mfg['city'];
            $mfgArr['phone'] = $mfg['phone'];
            $mfgArr['websiteurl'] = $mfg['websiteurl'];
            $mfgArr['linkedin_url'] =$mfg['linkedin_url'];
            if (!$this->find_key_value($manufacturerArr, 'id', $mfgArr['id'])) {

                $chkFav = DB::table('user_list_details_temp')
                        ->where('type', 'manufacturer')
                        ->where('unique_id', $cookieId)
                        ->where('reference_id', $mfg['id'])
                        ->select('id as fav_yes')
                        ->first();
                $mfgArr['fav_yes'] = "";
                if (!empty($chkFav))

                    $mfgArr['fav_yes'] = $chkFav->fav_yes;
                // Check if this product exists in non-logged in fav list

                $manufacturerArr[] = $mfgArr;
            }

            $recSecFeatured['address'] =    $mfg['address'];
            $recSecFeatured['city']    =    $mfg['city'];
            $recSecFeatured['phone']   =    $mfg['phone'];
            $recSecFeatured['websiteurl']   =     $mfg['websiteurl'];
            $recSecFeatured['linkedin_url'] =     $mfg['linkedin_url'];
            $recSecFeatured['mfg_id']       =     $mfg['id'];
            $recSecFeatured['mfg_name']     =     $mfg['name'];
            $recSecFeatured['mfg_logo']     =     $mfg['logo'];
            $productSection = Section::where('id', $productFeatured->section_id)->first();
            $recSecFeatured['sec_id'] = $productSection['id'];
            $recSecFeatured['sec_code'] = $productSection['code'];
            $recSecFeatured['sec_name'] = $productSection['name'];
            $recSecFeatured['slug'] = str_slug($productFeatured->name);
            // Check if this product exists in non-logged in fav list
            $chkFav = DB::table('user_list_details_temp')
                    ->where('type', 'product')
                    ->where('unique_id', $cookieId)
                    ->where('reference_id', $productFeatured->id)
                    ->select('id as fav_yes')
                    ->first();
            $recSecFeatured['fav_yes'] = "";
            if (!empty($chkFav))
                $recSecFeatured['fav_yes'] = $chkFav->fav_yes;
            // Check if this product exists in non-logged in fav list


            $featuredProductsIdsArr[] = $productFeatured->id;
            $prodFeatured[] = $recSecFeatured;
        }

        //echo "<pre>";print_r( $prodFeatured );exit;

    /***
        *
        * @author Muneeb Faruqi
        * @todo grouped prodFeatured on division name to each product under its certain division...
        **/
        $new_test = collect($prodFeatured)->groupBy('division_name')->toArray();
        $data['leedProducts'] = $new_test;
        $data['filterArray']=$filterArray;
        /*$data['leedProducts'] = $prodFeatured;*/
    /*@Muneeb Faruqi Changes Ends*/
        $data['leedManufacturer'] = $manufacturerArr;
        //$data['leedDivision'] = $divisionsArr;
        $data['leedDivision'] = $divisionsFeatured->toArray();
        $data['leedSection'] = $sectionsFeatured->toArray();
        $data['leedManufacturers'] = $manufacturersFeatured->toArray();

        // dd($manufacturersFeatured->toArray());

        // SEO Code for this page //
        $data['seoPageTitle'] = "Collaborative for High Performance Schools (CHPS.net) product database - Zero Docs";
        $data['seoPageDescription'] = "Pre-Approved low-emitting collaborative for high performance schools CHPS products for construction projects, schools, office and healthcare.";
        $data['seoPageKeywords'] = "Collaborative for high performance schools, LEEDv4 low emitting products, California Department of Public Health CDPH low-emission testing method for CA Specification 01350";
        // SEO Code for this page //
        // Start Cookie End Code
        $data['cookieId'] = $cookieId;

        $data['slug'] = $slug;
        $data['division_id'] = $division_id;
        $data['section_id'] = $section_id;
        $data['manufacturer_id'] = $manufacturer_id;

        $data['class'] = '';
        if (!empty($list) && $list === 'list') {
            $data['layout'] = 'list';
            $data['class'] = 'library-list-view';
        } else {
            $data['layout'] = 'card';
        }
        $data['showTooltipHelpText'] = "No";
        $showTooltipChpsPage = $request->session()->get('tooltip_chps_page', 'No');
        if($showTooltipChpsPage == 'Yes') {
            $request->session()->put('tooltip_chps_page', 'No');
            $data['showTooltipHelpText'] = "Yes";
        }
//Code by abdullah for sidebar filters data of manufacturers, products, leeds
        // $data['manufacturers'] = Manufacturer::where('status','active')->select('id','name')->orderBy('name', 'asc')->get();

        // dd($data['manufacturers']);
        $agent = new Agent();
        if($agent->isDesktop()) {
            $data['isDesktop'] = true;
        } else {
            $data['isDesktop'] = false;
        }

        $data['leed_records'] = DB::table('leed_tags')->where('leed_tags.status', 'active')
        ->whereIn('products.status', ['active'])
        ->where('products.division_id', '>', 0)
        ->where('products.section_id', '>', 0)
        ->where('products.manufacturer_id', '>', 0)
        ->join('products_selected_leeds', 'leed_tags.id', '=', 'products_selected_leeds.leed_id')
        ->join('products', 'products_selected_leeds.product_id', '=', 'products.id')
        ->orderBy('leed_tags.description', 'asc')
        ->select('leed_tags.description', 'leed_tags.id', 'leed_tags.parent_id', DB::raw('COUNT(DISTINCT products_selected_leeds.product_id) as products_count'))
        ->groupBy('leed_tags.id')
        ->get();

/***
*
* @author  Muneeb Faruqi
* @todo Manipulated the below array according to $new_test
*/

foreach($data['leedProducts'] as $all_manufacturers){

    foreach($all_manufacturers as $manufacturer_new){
        $list_all_manufacturers[] = array('mfgg_name' => $manufacturer_new['mfg_name'], 'mfgg_id' =>$manufacturer_new['mfg_id'],
            'product_name' => $manufacturer_new['name'], 'product_id' => $manufacturer_new['id']);
    }
    // $list_all_manufacturers[] = $all_manufacturers['mfg_name'];
}

/*@Muneeb Faruqi Changes Ends*/

$data['list_all_active_manufacturers'] = array_unique($list_all_manufacturers, SORT_REGULAR);

// dd($data['list_all_active_manufacturers']);
// unique by mfgg_name
$data['manufacturers'] = $this->unique_multidim_array($data['list_all_active_manufacturers'],'mfgg_name');

if($request->ajax()){
    $data['checkedManufactureArray'] = $request->manufacturer;
}else{
    $data['checkedManufactureArray'] = array(); 
}

        if ($cookieExists) {
            if($request->ajax()){

                // dd($checkedManufactureArray);
                    // return view('guest::new_design_frontend.ajax',$data);
                    return  view('guest::new_design_frontend.product-library')->with($data); 

            }else{
                return  view('guest::new_design_frontend.product-library')->with($data); 
            }
            // return view('guest::newcollaborative', $data);
                    //  dd($data);   


        } else {
            // $this->sendResponseWithCookie('guest::newcollaborative', $data, $cookieId);
            $this->sendResponseWithCookie('guest::new_design_frontend.product-library', $data, $cookieId);
        }


}

```
\$\endgroup\$
0
1
\$\begingroup\$

If statements without brackets work but it's hard to read and will trip you up eventually.

if (!empty($cookieId))
            $cookieExists = true;

This code is redundant

if($agent->isDesktop()) {
            $data['isDesktop'] = true;
        } else {
            $data['isDesktop'] = false;
        }

and can be replaced with

$data['isDesktop'] = $agent->isDesktop();

This variable is created and only used to be reassigned,

$new_test = collect($prodFeatured)->groupBy('division_name')->toArray();
$data['leedProducts'] = $new_test;

change to

$data['leedProducts'] = collect($prodFeatured)->groupBy('division_name')->toArray()
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.