Laravel delete image from folder


Laravel delete image from folder – The Laravel delete image from folder is used to delete image from the specific directory.


Laravel delete image from folder | with full Example.

Let us understand how to delete image from the folder.

Full example of delete image from the folder.

Now here i am going to explain how to delete image step by step.

First we need to create a DeleteImageController.php in controller directory.

Let’s look at a simple example.

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class DeleteImageControllerextends Migration
{
   
   public function destroy($id)
    {
    $file = Upload::find($id);
    $filename = Input::get('field name for file');
    $path = public_path().'/path/to/file/';

    if (!File::delete($path.$filename))
      {
      	Session::flash('flash_message', 'ERROR deleted the image!');
      	return Redirect::to('page name');
      }
    else
      {
      	$file->delete();
      Session::flash('flash_message', 'Successfully deleted the image!');
      return Redirect::to('page name');
      }    
  }
}

Route Path:-

Route::get('/deleteImage','DeleteImageController@destroy');

Advertisements

Add Comment

📖 Read More