
How to get list of all views file in laravel
How to get list of all views file in laravel
Hello everyone, in this post we will examine how to solve the "How to get list of all views file in laravel" programming puzzle.
-
Get all files of views directory in array
//config\filesystems.php 'disks' => [ 'views' => [ 'driver' => 'local', 'root' => base_path('resources/views'), ], ], //Code to get the list of all view files. $files = Storage::disk('views')->files(''); echo "<pre>"; print_r($files); //Import storage facade before calling the disk method on Storage facade. use Illuminate\Support\Facades\Storage;
You can get a list of all views files in laravel using this code snippet. This code snippet returns the files name in an array using the disk(‘views’)->files() method on Storage Facades. Use
use Illuminate\Support\Facades\Storage;
to call Storage fasade in your controller file. It only returns the files name which are directly inside of the views directory.Array
(
[0] => bsform.blade.php
[1] => get-ajax.blade.php
[2] => home.blade.php
[3] => posts.blade.php
[4] => welcome.blade.php
) -
Get all files within a views directory including all sub-directories
//config\filesystems.php 'disks' => [ // ... 'views' => [ 'driver' => 'local', 'root' => base_path('resources/views'), ], ], // app\Http\Controllers\<YourController>.php $files = Storage::disk('views')->allFiles(''); echo "<pre>"; print_r($files);
This code snippet returns an array of all files within a given directory (views) including all sub-directories. Basically this method returns all the files which are directly inside of the views directory or in its sub-directory in laravel. Here index.blade.php is the file under image directory which is a sub-directory of views directory.
Array
(
[0] => bsform.blade.php
[1] => get-ajax.blade.php
[2] => home.blade.php
[3] => image/index.blade.php
[4] => posts.blade.php
[5] => welcome.blade.php
)
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Count all and get 10 records after where condition in laravel
- How to get last month records in Laravel
- Get latest record by created at in Laravel
- Get products with number of orders in Laravel
- How to pass query string to url in laravel
- Ajax GET request in laravel
- How to get only time from created_at in laravel
- How to add active class to menu item in laravel
- Laravel delete all rows older than 30 days
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Seed database using SQL file in Laravel
- Redirect to previous page or url in laravel
- Remove array keys and values if it does not exist in other array in Laravel
- Link storage folder in laravel 8
- Create a record if not exist in laravel
- How to make Copy or Duplicate table row in laravel
- Display success message in laravel
- How to get all posts which contains comments in laravel
- Insert data with form validation using ajax in laravel
- Symlink(): No such file or directory
- Non-static method App\Http\Helper::myFunction() should not be called statically
- How to create belongstomany relation using custom name on custom pivot table
- Laravel specific table Migration
- Property [user] does not exist on this collection instance
- Print last executed query in laravel