Soft deleted records are getting fetched from database.
I have added soft delete to Category model. 'deleted_at' column is being set when I soft delete a record. But, when I fetch the result from database using
Category::latest('id')->paginate(20)
it is returning deleted records as well.
My Category model
class Category extends Model
{
use SoftDeletes;
protected $fillable = [
'name',
'slug',
'description',
'is_active',
'image',
];
}
Check query using telescope and it run this.
select * from `categories` order by `id` desc limit 20 offset 0
But it should run
select * from `categories` where `deleted_at` is null order by `id` desc limit 20 offset 0
I'm find my solution. I was used an trait that not mention in model here. on that trait constructor, i didn't call parent::__construct(). that was the problem. now i'm called parent::__construct(); in trait construct , and it worked.
public function __construct() {
parent::__construct();
}