What are the difference between softDelete() & delete() in Laravel?
In case when we used to delete in Laravel then it removed records from the database table.
$delete = Post::where(‘id’, ‘=’, 1)->delete();
To delete records permanently is not a good thing that’s why laravel used features are called SoftDelete. In this case, records did not remove from the table only delele_at value updated with current date and time.
Firstly we have to add a given code in our required model file.
protected $dates = ['deleted_at'];
After this, we can use both cases.
$softDelete = Post::where(‘id’, ‘=’, 1)->delete();
$softDelete = Post::where(‘id’, ‘=’, 1)->softDeletes();