Google News
logo
Laravel - Interview Questions
How to implement soft delete in Laravel?
Soft Delete means when any data row is deleted by any means in the database, we are not deleting the data but adding a timestamp of deletion.
 
We can add soft delete features by adding a trait in the model file like below.
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Post extends Model {

    use SoftDeletes;

    protected $table = 'posts';

    // ...
}
Advertisement