W3docs

create folder in laravel

In Laravel, you can create a new folder using the File facade's makeDirectory method.

In Laravel, you can create a new folder using the File facade's 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:

Example of how to create a new folder called "uploads" in the "public" directory in Laravel

<?php

use Illuminate\Support\Facades\File;

File::makeDirectory(public_path('uploads'), 0755, true);

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

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 PHP's native mkdir() function, but it only creates a single directory at a time.

Example of creating a folder using the mkdir() method of PHP

<?php

mkdir('path/to/directory', 0775, true);

You can also use Laravel's Storage facade to create directories on any configured disk. If no disk is specified, it defaults to the application's default disk.

Example of using the Storage facade of Laravel for creating directory in any storage disk

<?php

Storage::makeDirectory('path/to/directory');