I want to be able to soft delete users through the $user->delete();
method but it doesn't seem to work properly. It always hard deletes, no matter what I do. I've followed all the Laravel 4.2 documentation about it and I think I've configured Sentry correctly. Here is my code:
User.php
<?php
use Cartalyst\Sentry\Sentry;
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class User extends Cartalyst\Sentry\Users\Eloquent\User implements UserInterface, RemindableInterface
{
protected $fillabe = array('username','email','password','password_temp','code','active');
use UserTrait, RemindableTrait, SoftDeletingTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
//Soft deleting
protected $dates = ['deleted_at'];
public $timestamps = true;
}
Controller.php
public function postDeactivate()
{
$validator = Validator::make(Input::all(), array('password' => 'required|min:6'));
if ($validator->fails()) {
return Redirect::route('account-deactivate')->withErrors($validator);
} else {
try {
$user = Sentry::getUser();
if ($user->checkPassword(Input::get('password'))) {
Mail::send(
'emails.deactivate',
array('username' => $user->username),
function($message) use ($user) {
$message->to($user->email, $user->username)->subject('Hope to see you soon!');
}
);
if ($user->delete()) {
return Redirect::route('home') ->with('global','Account deactivated!');
} else {
return Redirect::route('account-deactivate')->with('global','Error!');
}
} else {
return Redirect::route('account-deactivate')->with('global','Wrong password.');
}
} catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
return Redirect::route('account-sign-in-get')->with('message','User not found!');
}
}
By the way, I've published the Sentry config file under
/vendor/cartalyst/sentry/src/config/config.php
and changed line 123 to
'model' => 'User',
I've also created the migration to add the 'deleted_at' column on my table, so I'm at a loss. Any help would be greatly appreciated.
Thanks in advance!