我已经将$table->softDeletes()添加到了迁移文件中,并且已经将protected $softDelete = true;添加到了我的模型中,并且我的表中确实包含了deleted_at。但是每当我调用delete()时,整个行都会被删除。这是我叫删除的方式:

Schedule::whereId($id)->whereClientId($client_id)->delete();


我究竟做错了什么?

最佳答案

万一有人碰到这个问题。您仍然可以在Laravel 5中使用SoftDeletes。只需使用softdeletes特性即可。

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; //<--- use the softdelete traits

class YourModel extends Model
{
    use SoftDeletes; //<--- use the softdelete traits

    protected $dates = ['deleted_at']; //<--- new field to be added in your table

    protected $fillable = [

    ];
}


您可以查看laravel docsThis great tutorial on how to softdelete

10-08 16:52