Laravel print array in blade php Laravel print array in blade php laravel laravel

Laravel print array in blade php


To just output the array in blade for debugging purposes:

        @php            var_dump($arr);        @endphp

Then use a foreach loop as mentioned.


From your question it appears as if you want to output the array for debugging purposes which as I have commented you can simply use <?php and ?> tags within your blade templates.

<?php dd($array); ?>

However, blade has a raw output tag pair which is {!! and !!}.

Once you're ready to display the output of your directory structure you should assign it to your view.

There are 2 quick ways of using it either with Reflection; inside your controller:

class WatchController extends Controller{    public function index(\Illuminate\Filesystem\Filesystem $filesystem)    {        $files = $filesystem->allFiles($watchFolderPath);        // Your code.        return view('name', ['files' => $files]);    }}

Or to call it from the container:

class WatchController extends Controller{    public function index()    {        $files = app('files')->allFiles($watchFolderPath);        // Your code.        return view('name', ['files' => $files]);    }}

Also you should be using the Filesystem, there is no need to reinvent the wheel – You should read the manual.


You should use @foreach:

@foreach ($watchFolder as $key => $value)    Key: {{ $key }}        Value: {{ $value }} @endforeach

Or

@foreach ($watchFolder as $w)    {{ $w->name }}    @endforeach