Skip to content
Advertisement

List Directories in Laravel

I’m trying to list all directories in this path public_path().'/assets/fe/img/portfolio'

enter image description here

dd(Storage::directories(public_path().'/assets/fe/img/portfolio'));

I kept getting [], I suppose to get 5.

Why ?

Advertisement

Answer

Storage::directories() try to find directories in storage/app/public folder, certainly because you have asked it to do so in your filesystems.php file.

add this in disks array in filesystems.php file

    'public' => [
        'driver' => 'local',
        'root'   => public_path(),
    ],

then you can use this syntax to get desired output

IlluminateSupportFacadesStorage::disk("public")->directories("assets/fe/img/portfolio")

assuming your public folder is in root directory and has following directory structure

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement