How to delete a model using php artisan?

How to delete a model using php artisan?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to delete a model using php artisan?

When you start building a Laravel application, the scaffolding tools make it incredibly easy to spin up new features. You run php artisan make:model User and suddenly you have a User class in your app/Models directory (or app/User in older versions) and a corresponding migration ready to be rolled out. The process feels seamless, but the reverse operation—removing that model entirely from your codebase—is where many developers pause. You might assume there is a direct counterpart command like php artisan delete:model, but looking at the CLI options reveals that no such tool exists in the Laravel core.

The absence of this command isn't an oversight; it's a deliberate architectural choice by the framework maintainers. Models are not just data containers; they are classes that define your application's domain logic, relationships, and often contain complex business rules. Deleting a file manually is dangerous because it leaves behind dead code references throughout your controller, service layer, and route definitions. If you simply remove the User.php file but forget to update the routes or controllers, your application will throw fatal errors about missing classes on every page load.

To safely "delete" a model in Laravel, you must treat it as a refactoring task rather than a simple file removal. The process involves three distinct phases: cleaning up the database schema, removing the class definition, and updating the codebase references.

First, address the migration. If the model was accompanied by a migration file (e.g., create_users_table.php), you need to decide whether to drop the data or rollback the migration. If the user data is no longer needed, you can run the migration with the --force flag or manually edit the migration to drop the table using $table->dropIfExists(). This ensures the database schema matches your current application state.

Next, remove the model class itself. There is no magic command to do this for you. You must navigate to the directory where the model resides—typically app/Models in modern Laravel versions or app in legacy setups—and delete the file manually using your terminal's file management tools:

rm app/Models/User.php
# Or for older structures
rm app/User.php

The most critical step, however, is auditing your codebase. Before touching the filesystem, search your project for references to the class you intend to remove. In Laravel, this usually means checking routes/web.php or routes/api.php. If you have a route defined like Route::get('/user', [UserController::class, 'show']), that route will break immediately after the model is deleted. You must either comment out the route, redirect it to a new endpoint, or delete the route definition entirely.

Similarly, scan your controllers and services for type hints or Eloquent queries like User::all() or $user = User::find(...). These references will result in Class 'App\Models\User' not found exceptions. You need to refactor these usages to point to a different model or remove the logic if it's no longer required.

Finally, clear your configuration cache if you have used any service provider registrations that tied specifically to that model. While Laravel 5 and later handle this largely automatically via autoloading, explicit imports in app/Providers/RouteServiceProvider.php or similar files might need manual cleanup.

There is no "safe" one-liner command because safety depends entirely on your specific application context. The framework expects you to manage dependencies manually. By systematically removing the migration, deleting the class file, and updating every reference in your controllers and routes, you ensure that the model is truly gone without leaving your application in a broken state. For more tips on Laravel architecture and best practices, resources like https://laravelcompany.com can be helpful when navigating complex refactoring scenarios.

Our network