Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

Laravel – Check If Directory Exists Before Create Directory

You can easily check if a directory exists or not using Laravel’s Storage class method, exists(). And there is a makeDirectory() method in Storage class, by using it, you can create a folder and you can set permissions to the folder.

Create a directory with Storage Facades


@method static bool makeDirectory(string $path)

Example script:

use Illuminate\Support\Facades\Storage;
if(!Storage::exists($path)) {
    Storage::makeDirectory($path); //creates directory

Create a directory with File Facades


@method static bool makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false)

Example script:

use Illuminate\Support\Facades\File;
if(!File::exists($path)) {
    File::makeDirectory($path, 0777, true); //creates directory

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments