Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sadok's avatar
Level 1

Class 'App\Http\Controllers\Storage' not found

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use App\User;
use App\Team;
use App\Club;

class TeamController extends Controller
{

public function destroy($id)
  {
    $team=Team::findOrFail($id);
    $team->delete();
    Storage::delete($team->logo);
    return response()->json(['data' => $team],200);
  }
}
0 likes
27 replies
xLukas's avatar

If you don't import your class at the beginning of the file and use it like this Storage::delete($team->logo); autoloader tries to find the class relatively to your current namespace. What is in your case App\Http\Controllers so autoloader look for class App\Http\Controllers\Storage . If you don't want autoloader look for class relatively to your current namespace you can add backslash in front of your class \Storage::delete($team->logo) or just import the class at the beginning of the file use Storage; and use it like you did. Checkout this link to learn more about namespaces PHP namespaces

2 likes
sadok's avatar
Level 1

i did try " use Storage " and it still returning 404 :(

rin4ik's avatar

with this?

$team=Team::findOrFail($id);
    \Storage::delete($team->logo);
    $team->delete();
    return response()->json(['data' => $team],200);
Dry7's avatar

or app('filesystem')->delete($team->logo)

sadok's avatar
Level 1

yes i tried that still the same issue and i ve allready run the cmd php artisan storage:link and nothing of these tries solved my issue

rin4ik's avatar

pls dd after each step

$team=Team::findOrFail($id);
dd('ok');    
\Storage::delete($team->logo);
    $team->delete();
    return response()->json(['data' => 'deleted'],200);

I think it can't find the team with that id . maybe you are trying to remove already removed team

xLukas's avatar

The reason why you have 404 can be several.

  1. Your destroy controller method "listen" for DELETE request but you do different type of request
  2. You using findOrFail($id) method which gives you 404 when model with given ID is not in DB.

Try to do dd($id) at the very beginning of the destroy method so we can see if it even hits your method.

sadok's avatar
Level 1

no i checked my data base and the team still exists

rin4ik's avatar

@sadok what do you have after this?

$team=Team::findOrFail($id);
dd($team);
sadok's avatar
Level 1
  public function destroy($id)
  {
    dd($id);
    $team=Team::findOrFail($id);
    $team->delete();
    \Storage::delete($team->logo);
    return response()->json(['data' => $team],200);
  }
sadok's avatar
Level 1

in postman i can see it returning the team id that i want to delete , but it doesn't get deleted

sadok's avatar
Level 1

@rin4ik the problem is that Storage can't be found witch is not logic , that's so weird, it's driving me crazy

xLukas's avatar

HTML forms cannot do DELETE request so you need to do form method spoofing manually. Postman can do DELETE.

<form action="YOUR_DELETE_ROUTE" method="POST">
    {{ method_field('DELETE') }}
    {{ csrf_field() }}
    <input type="submit">
</form>

Form Method Spoofing

1 like
xLukas's avatar

Notice the {{ method_field('DELETE') }} what generates <input type="hidden" name="_method" value="DELETE"> and tells laravel that this is DELETE REQUEST even the method is set to POST.

1 like
Cronix's avatar
Cronix
Best Answer
Level 67

This code is also in the wrong order...

$team=Team::findOrFail($id);
$team->delete();
\Storage::delete($team->logo);

You need to delete the $team->logo before you delete the $team. If you delete $team first, $team->logo doesn't exist any longer.

// import the storage facade
use Illuminate\Support\Facades\Storage;

public function destroy($id)
{    
    $team=Team::findOrFail($id);
    Storage::delete($team->logo);
    $team->delete();

    return response()->json(['data' => $team], 200);
}
3 likes
sadok's avatar
Level 1

@rin4ik that's true , i didn't notice that you changed the order. thank you very much, and thanks for all members for helping me and giving me many new informations that i can use in the future.

Cronix's avatar

Maybe if you took the time to actually explain it it would have been more obvious. He can choose whatever post helped him the most.

rin4ik's avatar

he wants to become a developer he should read and try to understand the code not the explanations! I've provided that code before you. maybe you just read my code and gave that answer I don't know.

Cronix's avatar

Sometimes explanations just help; it's part of teaching which is what the forum is about. You answer your way, I'll answer mine, but you shouldn't be telling the OP what post he needs to choose as the answer lol. That's just lame.

Shahrukh4's avatar

Try using Storage at top of class and after clearing all cache update the composer and give permissions to write logs to storage folder

    <?php
        namespace App\Http\Controllers;

        use Illuminate\Http\Request;
        use Illuminate\Http\UploadedFile;
        use Storage;
        use App\User;
        use App\Team;
        use App\Club;

      class TeamController extends Controller
      {

          public function destroy($id)
          {
             $team=Team::findOrFail($id);
             $team->delete();
             Storage::delete($team->logo);
             return response()->json(['data' => $team],200);
         }
     }

   b).   php artisan cache:clear
   c).   composer update
   d).   sudo chmod -R 0777 storage/
1 like
jet's avatar

Add this use Storage;

1 like

Please or to participate in this conversation.