Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of all views in Laravel 5.3?

Tags:

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

like image 911
Radovan Avatar asked Dec 06 '16 11:12

Radovan


People also ask

Where are views stored in laravel?

Views are stored in the resources/views directory. return view('greeting', ['name' => 'James']); }); As you can see, the first argument passed to the view helper corresponds to the name of the view file in the resources/views directory.

How do I return a view from a controller in laravel?

For example, if your view is stored at resources/views/admin/profile.blade.php , you may return it from one of your application's routes / controllers like so: return view('admin.profile', $data);

What are views laravel?

What are the views? Views contain the html code required by your application, and it is a method in Laravel that separates the controller logic and domain logic from the presentation logic. Views are located in the resources folder, and its path is resources/views.

How can we call controller method from view in laravel?

$varbl = App::make("ControllerName")->FunctionName($params); to call a controller function from a my balde template(view page).


1 Answers

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

like image 81
Sagar Rabadiya Avatar answered Sep 24 '22 08:09

Sagar Rabadiya