I'm making a course on Laravel Sanctum: MasteringAuth.com

Get all files except specific paths in Laravel

Constantin Druc ยท 27 Mar, 2021

Recently I found myself in need of filtering out some paths when grabbing all the files using the File facade.

Those paths that need to be excluded can be specific files or specific directories. So we need to support both.

To save us from repeating the filtering logic everywhere, we can setup a macro.

Laravel macros allow us to add custom functionality to existing Laravel components. In our case, the File facade.

We can register a macro inside the Appservice provider, under the boot method.