Check If Folder Exists Before Create Directory in Laravel
In this post, we will give you information about Check If Folder Exists Before Create Directory in Laravel. Hear we will give you detail about Check If Folder Exists Before Create Directory in Laravel And how to use it also give you demo for it if it is necessary.
Using Laravel’s Storage class function exists()
you can quickly determine whether a directory is present or not. Additionally, the Storage class has a makeDirectory()
function that you can use to create folders and specify their permissions.
Check If Folder Exists Before creating Directory in Laravel
Create a directory with Storage Facades
Syntax
@method static bool makeDirectory(string $path)
Example
use IlluminateSupportFacadesStorage;
if(!Storage::exists($path)) {
Storage::makeDirectory($path); //creates directory
}
Create a directory with File Facades
Syntax
@method static bool makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false)
Example
use IlluminateSupportFacadesFile;
if(!File::exists($path)) {
File::makeDirectory($path, 0777, true); //creates directory
}
Thank you for reading Folder Exists Before Create Directory in Laravel article. Hope this code and post will helped you for implement Check If Folder Exists Before Create Directory in Laravel. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs