To get all rows from a table, I have to use Model::all()
but (from good reason) this doesn't gives me back the soft deleted rows. Is there a way I can accomplish this with Eloquent?
Our records will be automatically deleted from the cache if users delete all the records from the table. But we can delete it from the cache only if we are using the model of Laravel Eloquent. In the first example, we are going to use the truncate() function, which is used to delete all the records.
Soft deleting the data allows us to easily view and restore the data with minimal work and can be a huge time saver when data is accidentally deleted. Laravel provides support for soft deleting using the Illuminate\Database\Eloquent\SoftDeletes trait.
To also get soft deleted models
$trashedAndNotTrashed = Model::withTrashed()->get();
Only soft deleted models in your results
$onlySoftDeleted = Model::onlyTrashed()->get();
Model::withTrashed()->get();
Property::withTrashed()->find($list->property_id);
or
// 1 is unique id of the table
Model::withTrashed()->find(1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With