Home > Blockchain >  Delete user with soft delete
Delete user with soft delete

Time:01-06

Hey I'm trying to delete user with soft delete i have added in table

$table->softDeletes($column = 'deleted_at', $precision = 0);

and in model use Illuminate\Database\Eloquent\SoftDeletes; use SoftDeletes;

in controller

   public function close(User $user)
    {
        $user->delete();
        return redirect('/');
    }

route

   <form method="POST" action="{{ route('close') }}">
        @csrf
        @method('DELETE')
        <button >
            Delete Account
        </button>
    </form>

it's redirect's to main page but in users deleted_at column null. So what's i'm doing wrong?

CodePudding user response:

add SoftDeletes trait to your User model

your code should be as such

use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Authenticatable
{
    use SoftDeletes;
}

CodePudding user response:

The route should be

<form method="POST" action="{{ route('close', ['user' => $user]) }}">
  •  Tags:  
  • Related