How to check if row is soft-deleted in Eloquent?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Efficiently Checking for Soft Deleted Rows in Laravel Eloquent Models Introduction: In the world of software development, data handling has become an essential aspect of any application. One particular feature that can be quite useful is soft-deletion. This allows developers to delete data from a database without permanently removing it by marking records as deleted. Laravel comes with built-in support for this functionality, making it easier to manage data states in your applications. In this blog post, we will explore how you can check if an Eloquent model object has been soft-deleted in the context of Laravel 5.1. Body: When dealing with soft deletes in Laravel, one important thing to consider is the difference between retrieving data and checking if a row has been deleted after obtaining the model instance. The provided code snippet checks for the existence of a "deleted_at" property on the Eloquent model object, which is set when a record undergoes soft deletion. However, it might not be an ideal solution as it involves hardcoding the property name, and can lead to future complications if that changes. Additionally, there could be better ways of checking whether a row has been soft deleted in Laravel 5.1 without having to rely on this approach. The following code snippet demonstrates an improved method for checking if an Eloquent model object has been soft-deleted: ```php if ($thing->trashed()) { // This row is soft deleted and can be handled accordingly } else { // The row exists (either not soft deleted or still available) and can be used as needed } ``` This solution encapsulates the logic for handling soft-deleted rows in a more elegant way. Using the "trashed()" method, you can easily check if the model instance was marked as soft-deleted without having to worry about the internal implementation of how Laravel tracks this state. This helps maintain code clarity and readability. Conclusion: Checking for soft-deleted rows in Eloquent models is a common requirement for any application that utilizes soft deletion for data management. In Laravel 5.1, using the "trashed()" method provides a cleaner solution for this task. It allows developers to easily check if an Eloquent model object has been marked as soft-deleted without relying on hardcoded property names or additional code logic. This approach leads to better maintainable and more efficient applications. In summary, when handling soft-deleted rows in Laravel 5.1 using Eloquent models, it's advisable to utilize the "trashed()" method rather than checking for a specific property name like "deleted_at". This approach ensures code clarity and readability while maintaining consistency with Laravel's built-in soft deletion functionality.