Home > Mobile >  How to access view folder in laravel and check there is any blade file have or not
How to access view folder in laravel and check there is any blade file have or not

Time:09-14

I have two folder in view file. like:

template1
template2

I want to see all the file list from specific folder. and check there is any specific blade file have or not. So i dont know how to do this.

thanks.

CodePudding user response:

If you want to list all views, you could use the File facade to get an array of all the files included in your views folder. This will not show vendor views unless they have been published.

use Illuminate\Support\Facades\File;

$views = collect(File::allFiles(resource_path('views')))
    ->map->getPathName()
    // ->filter(fn ($pathName) => ... ) // additional filtering
    ;

If you want to check if a specific view exists or not, the View facade has an exists method.

use Illuminate\Support\Facades\View;

View::exists('template1.some-view'); // returns true if template1/some-view.blade.php exists.

CodePudding user response:

I solved my problem from here.

https://laravel.com/docs/9.x/views#determining-if-a-view-exists

  • Related