title: Laravel 8: How to delete file in storage folder
body: <p>I currently have an API where it uploads and delete the PDF of the lesson. You see, whenever I delete the PDF, or make it null, it doesn't delete the file in my storage directory [C:\xampp\htdocs\drv-api\storage\app\public\uploads]</p>
  <p>My Lesson PDF Controller:</p>
  <pre><code>    &lt;?php
  
  namespace App\Http\Controllers;
  
  namespace App\Http\Controllers;
  use App\Models\LessonPDF;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Validator;
  use Illuminate\Support\Facades\File; 
  use Illuminate\Support\Facades\Storage;
  
  class LessonPDFController extends Controller
  {
      public function FileUpload(Request $request, $id)
      {
          $rules=[  
              'file'=&gt;'required|mimes:pdf',
          ];
          $validator = Validator::make($request-&gt;all(), $rules);
          if($validator-&gt;fails()){
              return response()-&gt;json($validator-&gt;errors(),400);
          }
          
          $file_mime_type = $request-&gt;file-&gt;getClientMimeType();
          // $original_file_name = $request-&gt;file-&gt;getClientOriginalName();
  
          $uploaded_files = $request-&gt;file-&gt;store('public/uploads/');
          // $uploaded_files = $request-&gt;file-&gt;storeAs('public/uploads/', $request-&gt;file-&gt;getClientOriginalName());
  
          $lesson = LessonPDF::find($id);
          $lesson-&gt;lesson_pdf = $request-&gt;file-&gt;hashName();
  
          $results = $lesson-&gt;save();
          if($results){
              return [&quot;result&quot;=&gt;&quot;PDF Added&quot;];
          }else{
              return [&quot;result&quot;=&gt;&quot;PDF Not Added&quot;];
          }
  
          // return [ &quot;result&quot;=&gt;&quot;$uploaded_files&quot;];
  
      }
  
  
      public function DeletePDF($id)
      {    
          $lesson = LessonPDF::find($id);
          if(is_null($lesson)){
              return response()-&gt;json('Record not found!', 401);
          }
  
          // $image_path = public_path().'/'.$lesson-&gt;file; unlink($image_path);
  
          // $image_path = storage_path().'public/uploads/'.$lesson-&gt;file;
          unlink(storage_path('app/public/uploads/'.$lesson));
  
          if (File::exists($image_path)) {
              //File::delete($image_path);
              unlink($image_path);
          }
          // Storage::delete($lesson-&gt;lesson_pdf);
          $lesson-&gt;update(['lesson_pdf' =&gt; null]);
              return response('PDF Deleted', 200);
  
      }
  
      }
  </code></pre>
  <p>My LessonPDF Model:</p>
  <pre><code>  &lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class LessonPDF extends Model
  {
      public $table = &quot;lesson&quot;;
      use HasFactory;
  
      protected $fillable = [
          'lesson_pdf',
      ];
  
      // protected $guarded = [];
  }
  </code></pre>
  <p>Any kind of help would be appreciated. Thank you!</p>