How to delete controller in Laravel 10 using command line
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
How to Delete Controllers in Laravel 10 Using the Command Line
As developers, we often rely on the power of the command line for repetitive tasks. When you use Artisan commands like php artisan make:controller to scaffold new files, it’s natural to wonder if there’s an equally powerful command to tear them down. While Laravel's primary focus is on building applications and managing data structures, the actual deletion of generated files falls into the realm of standard operating system commands.
This guide will walk you through the most effective and efficient ways to delete a controller—or any other file—in your Laravel 10 project using only the command line.
Understanding the Process: Creation vs. Deletion
When you run php artisan make:controller AuthLoginRegisterClass, Laravel scans the filesystem, creates the necessary directory structure, and populates the file with default content. This is a creation operation managed by the framework’s Artisan tool.
However, deleting that file is fundamentally a file system operation handled by your operating system (Linux, macOS, or Windows Command Prompt/PowerShell). There is no built-in php artisan delete:controller command because this specific action isn't considered a core architectural function of Laravel itself; it’s a deployment and maintenance task.
Method 1: The Direct Approach (Manual Deletion)
For simple, one-off deletions, the most straightforward method is direct file system manipulation. This approach is perfect for quick fixes when you are working interactively in your terminal.
To delete the controller generated by the command php artisan make:controller AuthLoginRegisterClass, you navigate to the project root and use the appropriate shell command:
rm app/Http/Controllers/AuthLoginRegisterClass.php
Explanation:
rm: This is the standard Unix command used to remove (delete) files or directories.app/Http/Controllers/: This is the specific path where Laravel stores all controller files by default.AuthLoginRegisterClass.php: This is the exact filename you wish to delete.
Caution: Always double-check the path before executing rm. Deleting the wrong file can lead to serious errors in your application structure. When dealing with large projects, ensure you are working within the correct project root directory as outlined by best practices when managing Laravel applications, as discussed on sites like laravelcompany.com.
Method 2: Automated Deletion via Shell Scripting (The Power User Approach)
If you frequently need to clean up files—perhaps in a deployment script or during automated testing setup—relying on manual execution is inefficient. For bulk operations, scripting provides immense power and repeatability.
You can create a simple shell script to handle the deletion of multiple controllers at once. This is especially useful when managing large numbers of routes or resource files.
Here is an example of how you might write a script to clean up all generated controllers matching a certain pattern:
#!/bin/bash
# Define the directory where controllers reside
CONTROLLER_DIR="app/Http/Controllers"
echo "Starting cleanup of controllers in $CONTROLLER_DIR..."
# Find all PHP files ending with .php in the controller directory and delete them
# Use find for robust searching across subdirectories if necessary, though simple rm is sufficient here.
find "$CONTROLLER_DIR" -name "*.php" -type f -exec rm {} \;
echo "Controller cleanup complete."
How this works:
This script uses the find command to locate every file ending in .php within the app/Http/Controllers directory and executes the rm command on each one found. This method ensures that no matter how many controllers you generate, the cleanup process is executed consistently and automatically, saving significant time during development and deployment cycles.
Conclusion: Command Line Efficiency
Deleting files in a Laravel project via the command line isn't about finding a magic Artisan command; it’s about leveraging the underlying operating system tools to manage your file structure efficiently. Whether you opt for the direct rm command for a single file or implement a robust shell script for bulk cleanup, mastering these commands is a crucial skill for any senior developer working with the Laravel ecosystem. Embrace the power of the shell to streamline your workflow and keep your project directory clean and organized.