Site Admin
Site Admin Founder of MeaningArticles
2266 Views

Laravel 7.x and 6.x Create Directory If Not Exists

Hello Dev.

In this Article, we will guide you how to create folder in storage in laravel 6 application. we are able to without difficulty create directory if now not exists the use of File or Storage facade in laravel 6 project. i can give you easy and extra solution of laravel 6 make folder in public folder or storage folder.

i'm able to come up with extra way to create folder in public folder in laravel 6. you may see i can use File facade to create folder, Storage facade will use to create directory from storage in laravel 6 and also i'm able to provide you with easy code core php to create folder.


Using File System:

public function createDirecrotory(Request $request)
{
    $path = public_path('upload/meaningarticles.com');

    if(!File::isDirectory($path)){
        File::makeDirectory($path, 0777, true, true);
    }

    dd('done');
}


Using Storage System:

public function createFolder()
{
    $response = Storage::makeDirectory('upload/meaningarticles.com');
    dd($response);
}


Using Core PHP:

public function removeFolder()
{
    $folderPath = public_path('uploads');
    $response = mkdir($folderPath);
    dd($response);
}

i'm hoping it assist you to, thanks for visit my article if you like my article then proportion together with your friend and social platform.