Home > Software design >  why Resource Controllers not working in laravel 8?
why Resource Controllers not working in laravel 8?

Time:09-27

route link

    <a href="{{ route('users.destroy', $user->id) }}">Delete</a>

define route

    Route::resource('users', UserController::class);

controller function

    public function destroy($id)
        {
            $delete = DB::table('users')->delete($id);
            if ($delete) {echo 'success';}
        }

CodePudding user response:

in the delete route, the method should be delete, you can write it in this way

<form action="{{ route('users.destroy', $user->id) }}" method="post">
   @csrf
   @method('delete')
   <button type="submit">Delete</button>
</form>

CodePudding user response:

first of all you need to find specific id then delete the same one

$user = User::findOrFail($id);

$user ->delete();

  • Related