Я хочу иметь возможность мягко удалять пользователей с помощью метода $user->delete();
, но, похоже, он не работает должным образом. Он всегда жестко удаляет, независимо от того, что я делаю. Я просмотрел всю документацию по Laravel 4.2 и думаю, что правильно настроил Sentry. Вот мой код:
Пользователь.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;
}
Контроллер.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!');
}
}
Кстати, я опубликовал файл конфигурации Sentry в разделе
/vendor/cartalyst/sentry/src/config/config.php
и изменил строку 123 на
'model' => 'User',
Я также создал миграцию, чтобы добавить столбец «deleted_at» в свою таблицу, поэтому я в недоумении. Любая помощь будет принята с благодарностью.
Заранее спасибо!