create folder in laravel
In Laravel, you can create a new folder using the
makeDirectory method. This method takes the path of the new directory as its first argument and the file permissions as its second argument (in octal format).
Here is an example of how to create a new folder called "uploads" in the "public" directory:
use Illuminate\Support\Facades\File; File::makeDirectory(public_path('uploads'), 0777, true);
Note that the third argument passed to the
makeDirectory method is a boolean value that indicates whether to create parent directories if they do not exist. In this example, it is set to
true, so if the "public" directory does not exist, it will be created automatically.
You can also create a folder using the
mkdir() method of PHP, but it only create a single directory at a time.
mkdir('path/to/directory', 0775, true);
You can also use
Storage facade of Laravel for creating directory in any storage disk.
Finally, you can create a folder using
create method, which creates a new file at the given path. If a file with the same name already exists, it will be truncated to zero length.
It will create a folder if it is not exist otherwise it will truncate the exist one.