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 add script on specific view file in laravel while extending layout
- Class 'App\Rules\Hash' not found in Laravel
- How to get the id of last record from collection object in laravel view
- How to remove P tag from CkEditor in Laravel?
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- How to check data inserted or deleted in pivot after toggle method
- Call to undefined method App\Models\User::follow()
- How to display user profile after login in laravel
- Redirect to another view from controller in laravel
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- Method chaining in Laravel
- Display first n record from collection in laravel view
- Get today records in Laravel
- How to disable timestamps in laravel
- Generate random string lowercase in Laravel
- Method Illuminate\Events\Dispatcher::fire does not exist
- How to check duplicate entry in laravel
- Update record after find method in lavavel
- How to call Laravel route in jQuery
- Multiple Level eager loading in Laravel
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- Convert multidimensional array to single array in Laravel
- How to pass query string to url in laravel
- Delete records with relationship in laravel