<?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);
}
}
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
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.
You need to delete the $team->logobefore 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);
}
@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.
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.
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.