Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Eloquent - Soft deleting is not working

I have added $table->softDeletes() to my migration file and have added the protected $softDelete = true; to my model, and I do have the deleted_at in my table. But whenever I call delete(), the entire row is deleted. Here is how I am calling my delete:

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

What am I doing wrong?

like image 446
Kousha Avatar asked Jan 29 '26 19:01

Kousha


1 Answers

In case somebody bumps into this question. You can still use SoftDeletes in Laravel 5. Just use the softdeletes trait.

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 = [

    ];
}

You can view laravel docs or This great tutorial on how to softdelete

like image 87
Ikong Avatar answered Jan 31 '26 21:01

Ikong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!