Home > database >  Dump within map function in Laravel
Dump within map function in Laravel

Time:04-28

Within a map function i would like to use dd(); dump but i only get the first object. When i use print_r(); within a map function i get all objects

$valeurCategorieCible = $CategoriesItineraires->map(function ($item) {
            return $item->ciblesParCategorie->map(function ($ciblesParCategorie) {
                return $ciblesParCategorie->cibles->map(function ($items) {
                    print_r($items); // Return all objects
                    dd($items); // Return only the first object then stop !
                });
            });
        });

CodePudding user response:

According to the documentation for dd() it "dumps the given variables and ends execution of the script" - the important part is "ends execution of the script"!

If you don't want to end execution use dump() instead of dd()

  • Related