Is there any way to soft delete all the existing rows in a table? I have tried ( Prospect::delete(); ) it deleted all the rows permanently, But it doesn't work in soft deleting.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
look at this soft delete
use this trait in your model :
and add this to your model and database schema :
model:
database schema
Now, when you call the delete method on the model, the deleted_at column will be set to the current date and time. And, when querying a model that uses soft deletes, the soft deleted models will automatically be excluded from all query results.
To determine if a given model instance has been soft deleted, use the trashed method:
If you are using Laravel framework older than 4.2, then you can set the soft delete in your model as,
If you are using Laravel framework 4.2, then you can set the soft delete in your model as,
If you are using Laravel framework above 4.2, then you can set the soft delete in your model as,
I hope you are using Laravel 5. So you can use the third method.
It usually not delete rows in database.You should add a column isActive etc. and set it (1/0) or (true/false). if you want show rows,you should "Select * from table Where isActive=1"