skip to Main Content

I have created controller in laravel using command php artisan make:controller AuthLoginRegisterClass

Now, I want to delete it using only command line, can you please help me ?

Thank you

3

Answers


  1. You can do so by running the following command

    rm app/Http/Controllers/AuthLoginRegisterClass.php
    
    
    Login or Signup to reply.
  2. Firstly, open the command prompt and navigate to the root directory of your Laravel project-

    cd /path/to/your/Laravel/project
    

    Now, use the ‘rm’ command followed by the path to the controller like-

    rm app/Http/Controllers/ExampleController.php
    

    (if your file is located in the app/Http/Controllers)
    after executing this command the controller file will be permanently deleted from your project.

    Login or Signup to reply.
  3. You can utilize the power of shell script to delete the file using terminal. I created a script to delete the file in controllers folder. It will search for the file inside the Controllers folder and delete it once it finds it. Here’s the script:

    delete.sh
    #!/bin/bash
    
    FILE_NAME=$1
    
    # Find the file in the Controllers directory
    FILE_PATH=$(find ./app/Http/Controllers -name "$FILE_NAME" -type f -print -quit)
    
    # Check if the file exists
    if [ -n "$FILE_PATH" ]; then
        # Remove the file
        rm "$FILE_PATH"
    
        echo "File deleted successfully."
    else
        echo "File not found."
    fi
    

    You can give this file appropriate permissions i.e. executable with chmod +x delete.sh and use it with the following command:

    ./delete.sh FooBarController.sh

    Hope this helps in resolving the issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search