Laravel - Collection::delete method does not exist
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Laravel Eloquent Deletion Mystery: Why Collection::delete() Fails on Model Deletion
As a senior developer navigating the complexities of the Laravel ecosystem, we often encounter subtle yet frustrating errors when dealing with Eloquent model lifecycle events. The issue you are facing—where attempting to delete a model results in an error like method [...]Collection::delete does not exist—stems from a common confusion between how Eloquent handles instance operations, static methods, and collection manipulation.
This post will demystify why this occurs and show you the correct, idiomatic way to trigger your model's boot methods, such as deleting(), when performing deletions in Laravel.
Understanding Eloquent Deletion Mechanics
The error message you encountered highlights a misunderstanding regarding scope and context within Eloquent. When you interact with an Eloquent model (an instance), you are dealing with an object that has specific methods tied directly to that record, not necessarily static collection methods unless you explicitly use the Query Builder.
Instance Deletion vs. Collection Deletion
- Instance Deletion (
$model->delete()): When you callUser::find(6)->delete(), you are invoking an instance method on that specific model object. Eloquent is designed to hook into the lifecycle events—likedeletingordeleted—when this operation occurs. The methods defined in your model'sboot()static block are triggered precisely for this purpose. - Collection Deletion (
$collection->delete()): The methoddelete()on a Laravel Collection object is designed for deleting items from the collection itself, not for executing database deletion logic tied to an Eloquent model relationship or lifecycle hooks across multiple models in the way you are attempting. This is why calling it on a static result (like from Tinker) fails; the necessary Eloquent context isn't properly established for that specific operation.
Your goal is to execute the logic defined in static::deleting(function ($user) { ... }) when a record is removed from the database. The correct path involves ensuring you are using the proper Eloquent methods.
Correctly Triggering Model Events on Deletion
To successfully trigger your custom deletion logic, you must rely on standard Eloquent operations that interact with the database layer. Whether deleting a single model or a group of models, the mechanism for triggering events remains consistent.
Scenario 1: Deleting a Single Model (The Preferred Way)
If you are deleting one specific user, use the instance method:
use App\Models\User;
$user = User::find(6);
if ($user) {
// This will trigger the deleting() model event defined in your boot() method.
$user->delete();
}
This approach correctly passes the necessary context to Eloquent, allowing your custom logic (like deleting related posts or handling file cleanup within deleting()) to execute flawlessly. This principle is fundamental to robust data management in Laravel; understanding these hooks is key when building complex applications utilizing features like those found on laravelcompany.com.
Scenario 2: Deleting Multiple Models (Mass Deletion)
If you are deleting a group of users, use the Eloquent query builder's delete method:
use App\Models\User;
// This triggers the deleting() event for every user in the resulting collection.
$users = User::where('status', 'inactive')->get();
$users->delete();
When you use Model::delete(), Eloquent handles iterating through the results and triggering the necessary model events for each record, ensuring that your custom logic is executed consistently across all affected models.
Refactoring Your Model Logic
Reviewing your provided User model, your implementation of the deleting hook is excellent for managing related data (posts and profile files). Ensure that any file operations inside this hook are robust, especially concerning server paths, as demonstrated in your example:
// Inside static::deleting(function ($user) { ... })
$user->posts->delete(); // Correctly handles relationship deletion.
// ... rest of the logic for profile updates and file unlinking
By sticking to instance methods ($model->delete()) or query builder methods (Model::where(...)->delete()), you leverage Eloquent’s built-in event system correctly, avoiding ambiguity with static collection methods.
Conclusion
The confusion surrounding Collection::delete() versus model deletion stems from conflating collection manipulation with Eloquent's database interaction layer. For triggering model lifecycle events like deleting, always operate on an Eloquent instance or a query builder result. This ensures that the necessary context is passed to the model, allowing your boot methods to execute as intended. Mastering these distinctions is a critical step in writing clean, maintainable, and powerful code within the Laravel framework.