Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to leverage the glob method of Filesystem class with StorageFacade?

This is concerning Laravel 5.

I can see in Illuminate\Filesystem\Filesystem a method called glob($pattern, $flags = 0)

Unfortunately, this method is not reflected in the default FilesystemAdapter shipped with Laravel 5.

This would be great, due to the fact that I would need to do something like Storage::disk('local')->glob([_]*[.blade.php]); (in order to get all stored blade files starting with an underscore.

What is the cleanest way to achieve this?

like image 996
Réjôme Avatar asked Apr 19 '15 12:04

Réjôme


1 Answers

I think you cannot run glob here, but you could get all files and then filter them, for example:

$files = array_filter(Storage::disk('local')->files(), function ($file)
{
    return preg_match('/_(.*)\.blade\.php$/U', $file);
});

Of course you need to decide to use files or allFiles (recursively) depending on your needs. Probably it's not the best solution if you have thousands of files but if you don't it should be enough

like image 73
Marcin Nabiałek Avatar answered Nov 12 '22 13:11

Marcin Nabiałek