![]() The destroy() method accepts an array of primary keys and deletes the. Let's assume that you want to keep users for a while after they deleted their account so that you are able to restore them. You can use the destroy() method in Laravel Eloquent to delete multiple records. After that,you are good to go and soft deletes work instantly. You can simply add a new database column to your Laravel Model and use the SoftDeletes trait on your model. The feature that you are looking for is soft-deleting in Laravel. In other scenarios you can introduce the concept of a trash that your users know from their desktop and delete trashed records after a while. That’s all through this tutorial, you have learned how to use softdelete in laravel apps.It's common that a user in your applications makes mistakes and deletes data by accident – even if you show them countless warnings before they delete the record from your database. Use Illuminate\Database\Eloquent\SoftDeletes With Eloquent: App\Model::where ('mobilenumber', '0123456789')->delete () With the Query Builder: DB::table ('sometable')->where ('mobilenumber', '0123456789')->delete () EDIT The above will delete all rows with mobilenumber 0123456789. Use Illuminate\Database\Eloquent\Factories\HasFactory Now, open post.php model and add Illuminate\Database\Eloquent\SoftDeletes facade in model and use SoftDeletes class is as follows:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |