Search code examples
laravel-5.3

How to get list of all views in Laravel 5.3?


I'm trying to configure autocomplete input with all created blade views so is there option to get an array of all views? There is View::exists() to check for specific view but how to get all of them?

public function index(){   
$allviews = Storage::files('');     
return view('pages.dashboard', ['allviews' => $allviews]);  
} 

In my view I have this code

@foreach($allviews as $view)
<li>{{ $view }}</li>
@endforeach  

It only shows .gitignore file


Solution

  • use File facade to scan the directory and give content of it. check here https://laravel.com/docs/5.3/filesystem#directories

    configure your view disk in config/filesystems.php add below snippet in disks array :

    'disks' => [
    
        // ...
    
        'views' => [
            'driver' => 'local',
            'root' => base_path('resources/views'),
        ],
    ],
    

    Storage::disk('views')->files('') //will list all directory and contents available in resources/views

    Storage::disk('views')->files('auth') //will give content of resources/views/auth directory