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
- How to update record after save method in Laravel
- Display message with session flash using bootstrap alert class in laravel
- How to get specific columns using Laravel eloquent methods
- 419 page expired error in Laravel
- Input file with max size validation in laravel
- Split an Eloquent Collection by half in Laravel
- How to create belongstomany relation using custom name on custom pivot table
- Laravel route parameter
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- Validation errors for multiple forms on same page Laravel
- Include External CSS and JS file in Laravel
- How to get records in random order in laravel
- Permanently delete a record in laravel
- Laravel 10 starter app using breeze on live server
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- How to prevent host header attack in Laravel
- Delete all related comments on deleting a post in Laravel
- How to automatically update the timestamp of parent model in Laravel
- How to check duplicate entry in laravel
- Create records using relationship in laravel
- Get last record from table in laravel
- Get duplicate records in laravel
- How to validate form input data in laravel
- Setup laravel project with docker
- How to get route method name in Laravel