Posts Learn Components Snippets Categories Tags About

How to Create Directory in Laravel Storage if Not Exists

Learn how to create a directory in Laravel storage if it does not exist programmatically. Learn how to make use of the Storage facade and different types of disks to access the filesystem in Laravel.

Created on Sep 01, 2021


To programmatically create a directory in Laravel storage you can make use of the "Storage" facade provided by Laravel. The method is "makeDirectory()" and this accepts the path of the directory.

Do note that it supports a nested path so you can go as deep as you want it to.


How to specify the Storage Disk?

To specify the storage disk for example "s3" or the "public" disk you can call the "disk()" method as follows.

Do note that you will have to execute the code for Laravel to create the directory. For example creating a route endpoint to create the directory.

Route:get('create-directory', function () {
Now when you visit the "/create-directory" endpoint the directory will be created.

Snippets by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.


PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets