phplaraveldumpdd

dd() within map function in Laravel only shows first object


Within a map() methid call, I would like to use dd() to 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 !
        });
    });
});

Solution

  • 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()