Laravel 5 - SoftDelete无法正常工作

时间:2017-11-10 14:04:34

标签: laravel laravel-5 laravel-5.3 laravel-eloquent soft-delete

我已经在网络和StackOverflow本身进行了大量搜索,但是我无法找到问题的解决方案。

软删除只是拒绝工作。数据库具有deleted_at字段。用户模型具有所需的一切,但是当我调用Delete()方法时,数据仍然被硬删除。我不知道自己做错了什么。

Laravel版本:5.3.31

破坏方法

public function destroy($id)
{
    //$this->authorize('delete', User::class);
    $user = User::find($id);

    if (empty($user)) {
        Flash::error('User not found');

        return redirect(route('users.index'));
    }

    $user->Delete();

    Flash::success('User deleted successfully.');

    return redirect(route('users.index'));
}

用户模型

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Model
{
    use SoftDeletes;

    public $table = 'users';

    const CREATED_AT = 'created_at';
    const UPDATED_AT = 'updated_at';


    protected $dates = ['deleted_at'];


    public $fillable = [
        'name',
        'email',
        'password',
        'role',
        'remember_token'
    ];

    protected $casts = [
        'id' => 'integer',
        'name' => 'string',
        'email' => 'string',
        'password' => 'string',
        'role' => 'string',
        'remember_token' => 'string'
    ];


    public static $rules = [
      'name' => 'required|max:255',
    ];
}

我很感激能帮助我解决这个问题的任何事情。

提前致谢。

0 个答案:

没有答案