In this example, you learn the laravel create the directory if doesn’t exist, how to create folder in storage in laravel, Create a folder if does not exists in laravel.

isDirectory() function check if directory exists in laravel application. makeDirectory() function is create directory in laravel application. We will show how to create a folder in the public folder when a folder does not exist.


Example:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use File;

class UserController extends Controller
{
    public function index(){
        $path = public_path('upload/webtuts');

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

I hope you understand of create directory if doesn’t exists in laravel and it can help you…