skip to Main Content

what is problem ?

<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use IlluminateHttpUploadedFile;
use AppUser;
use AppTeam;
use AppClub;

class TeamController extends Controller
{

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

4

Answers


  1. Maybe you need to declare a use statement for storage

    use IlluminateSupportFacadesStorage;

    Login or Signup to reply.
  2. namespace AppHttpControllers;
    use IlluminateHttpRequest;
    use IlluminateHttpUploadedFile;
    use AppUser;
    use AppTeam;
    use AppClub;
    

    add this

    use IlluminateSupportFacadesStorage;
    
    Login or Signup to reply.
  3. if ($team->logo != null && file_exists(storage_path(‘app/public/’ . Path $team->logo ))) {
    unlink(storage_path(‘app/public/’ . Path $team->logo));
    }

    Path – enter your logo path

    Login or Signup to reply.
  4. 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 IlluminateSupportFacadesStorage;
    
    public function destroy($id)
    {    
        $team=Team::findOrFail($id);
        Storage::delete($team->logo);
        $team->delete();
    
        return response()->json(['data' => $team], 200);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search