I am working with blade laravel, I need to access the inner elements of an array that I return to my view from the controller, this is the result when I do a dd [![Array][1]][1]
I am working with blade laravel, I need to access the inner elements of an array that I return to my view from the controller, this is the result when I do a dd [![Array][1]][1]
What I imagine you have done is ask by debugging dd() your variable from the controller. And what you want is to access the data of that array from the views if I have not misunderstood. It is true that the question leaves much to be desired, however, I will give you a quick answer.
There are several ways/methods to pass data to views. I explain 2 and the rest in the documentation, I would recommend you take a look at it.
When you return in your controller to the view, you can do
Return view('carpeta.plantilla', compact('array,objeto,array2,objeto2'));
In this first way, you can pass as many arrays as you want, although generally, if it is a simple array or array, I recommend using the second option.
With the first option, for example, you could do a "query for database entries in your controller", directly store the query or object in a variable and pass it through compact.
Then in your sights, just do
@foreach($objeto as $obj) {{ $obj->id }} @endforeach
Accessing each object in each turn, and its id within it.
As a second option you can use "With"
return view('carpeta.plantilla')->with($array);
And the reason why I recommended you to use the with for simple and/or associative arrays, is because from the views, you will be able to access the values of the array directly.
For example if you have
$array = ['parametro1' => 'grande', 'parametro2' => 'pequeño'];
return view('carpeta.plantilla')->with($array);
And in your views you just have to put:
{{ $parametro1 }} And you would automatically access the value of the array that you passed through with.
Let's say what you do with, is "keep variables accessible to the view"
My recommendation is 1st to think carefully about how you want or are going to show your data in the views and what use you are going to give them. The second step, go to the documentation and see what other different forms you could use and choose the one that best suits your logic and loading of it.
I hope it helps you.
Cheers!