Home Laravel How to Delete Directory in Laravel ?

How to Delete Directory in Laravel ?

by Shahriar Sagor

Hi Dev’s,
Today now on this article, i will teach you how can we remove a folder in Laravel 8. So we can delete directory then we use deleteDirectory() also with File object. Here i will show you How to Delete Directory in Laravel 8.

Now we can get our delete folder path then after we use our get path in this function.

So now this method will return true if it succeeds, false if it fails.

Example for Laravel

First need to create a folder like public/test/demo.

public function index()
{
    $folderPath = public_path('test');

    $dd = File::deleteDirectory($folderPath);

    dd($dd);
}

it will return true if this method is success, it will return false if this method fails.

Example for PHP

public function index()
{
    $folderPath = public_path('test');

    $dd = rmdir($folderPath);

    dd($dd);
}

it will return true if this method is success, it will return false if this method fails.

Read Also : How to get current route in laravel ?

Thanks for read. I hope it help you. For more you can follow us on facebook

close

You may also like