Create New Post

Laravel - Artisan Commands

In Laravel, Artisan is the command-line interface included with the framework. It provides a number of helpful commands for common tasks like database migrations, running tests, and generating boilerplate code. You can access Artisan by using the php artisan command in the terminal.

Here are some commonly used Artisan commands:

  1. Migrations:

    • php artisan migrate: Run any pending migrations.
    • php artisan migrate:rollback: Rollback the last database migration.
    • php artisan migrate:status: Show the status of each migration.
  2. Database Seeding:

    • php artisan db:seed: Seed the database with records.
  3. Generate Code:

    • php artisan make:model ModelName: Create a new Eloquent model.
    • php artisan make:controller ControllerName: Create a new controller.
    • php artisan make:middleware MiddlewareName: Create a new middleware.
    • php artisan make:migration MigrationName: Create a new database migration.
  4. Tinker (Interactive Shell):

    • php artisan tinker: Open the interactive REPL (Read-Eval-Print Loop) for Laravel.
  5. Routes:

    • php artisan route:list: List all registered routes.
  6. Clear Cache:

    • php artisan cache:clear: Flush the application cache.
    • php artisan config:clear: Remove the configuration cache file.
  7. Environment Configuration:

    • php artisan env: Display the current environment.
    • php artisan config:cache: Create a cache file for faster configuration loading.
  8. Queue Workers:

    • php artisan queue:work: Start processing jobs on the queue.
  9. Testing:

    • php artisan test: Run your application tests.
  10. Make Custom Artisan Command:

    • php artisan make:command CommandName: Create a new Artisan command.
  11. Optimizing for Production:

    • php artisan optimize: Combine and minify configuration files for faster performance.

These are just a few examples of the many Artisan commands available in Laravel. You can explore the full list of commands by running php artisan list in your terminal. Additionally, you can get help for any specific command by using the --help option, like php artisan migrate --help. This will display information about the available options and arguments for that command.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

45927