Laravel Create Folder If Not Exists Example

Sep 27, 2019

.

Admin

hi guys,

In this example, i will show you create folder in laravel. we can easily create directory in laravel. we can solved simply define the command then create directory if not exists in laravel.

you are just trying to use File::makeDirectory to create folder from public path.

solution for laravel


/**

* Show the application dashboard.

*

* @return \Illuminate\Contracts\Support\Renderable

*/

public function index(Request $request)

{

$path = public_path('upload/');

if(!File::isDirectory($path)){

File::makeDirectory($path, 0777, true, true);

// retry storing the file in the newly created path.

}

}

If return true this method success, return false this method fails.

solution for php

/**

* Show the application dashboard.

*

* @return \Illuminate\Contracts\Support\Renderable

*/

public function index(Request $request)

{

$file = public_path('images');

$result = mkdir($file);

dd($result);

}

If return true this method success, return false this method fails.

It will help you...

#Laravel

#Laravel 6