How to create a directory in laravel?

Member

by denis , in category: PHP Frameworks , 5 months ago

How to create a directory in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elisha_langworth , 5 months ago

@denis 

To create a directory in Laravel, you can use the Storage facade provided by Laravel. The Storage facade provides a simple way to interact with the filesystem in Laravel.


Here's how you can create a directory using the Storage facade:

  1. Import the Storage facade at the top of your file:
1
use IlluminateSupportFacadesStorage;


  1. Use the makeDirectory method provided by the Storage facade to create a new directory:
1
Storage::makeDirectory('path/to/new/directory');


Replace 'path/to/new/directory' with the path where you want to create the new directory. Laravel will create the directory for you if it does not already exist.


You can also pass a second argument to the makeDirectory method to specify the visibility of the directory (e.g., 'public' for public visibility). Here's an example:

1
Storage::makeDirectory('path/to/new/directory', 0777, true);


This will create a public directory with read, write, and execute permissions for everyone.