mardi 5 mai 2015

Laravel - can't get values from multidimensional array with blade

I am having trouble looping through a multidimensional array with blade in laravel. I am sending the data from the controller like so:

return View::make('store.categories')
            ->with('brands', $brands);

And if I die dump the data:

array (size=2)
  0 => 
    array (size=2)
      0 => string 'Fender' (length=6)
      1 => string '(2)' (length=3)
  1 => 
    array (size=2)
      0 => string 'Gibson' (length=6)
      1 => string '(1)' (length=3)

I've tried to use two @foreach loops but I couldn't get it to work:

@foreach($brands as $brand)
  @foreach($brand as $b)
  {{$b}}
  @endforeach
@endforeach

The above will output: Fender (2) Gibson (1).


I tried to get the 0 value for the $b to output Fender but it just prints the 0 position character for each of the items in the $b array:
@foreach($brands as $brand)
  @foreach($brand as $b)
  {{$b[0]}}
  @endforeach    
@endforeach

The above will output F ( G (.

I'm probably doing something terribly wrong. How can I get the output for the values 0 and 1 for the nested arrays individually? Any help is highly appreciated.

Aucun commentaire:

Enregistrer un commentaire