
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
- Wheredate in laravel not working
- How to create pivot table in laravel using migration
- How to print form data in laravel
- Route prefix with auth middleware in laravel
- How to get last year records count with month wise in Laravel
- How to get tomorrow and yesterday date in laravel
- Where to use whereNotNull eloquent in laravel
- Insert dummy data in users table Laravel
- How to validate URL with https using regex in laravel
- Laravel get single row by id
- Attempt to read property "avatar" on null in Laravel
- Use withCount() to get total number of records with relationship
- Composer\Exception\NoSslException
- How to create laravel project using composer
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- Get all users except the followings users in overtrue laravel-follow
- Link storage folder in laravel 8
- Redirect to previous page or url in laravel
- Pagination in laravel
- Always load the relationship data with eager loading in Laravel
- Laravel route redirect not working
- Update email with unique validation in laravel
- How to check if user has created any post or not in laravel
- Laravel get count with where condition
- Laravel URL validation not working