What is Artisan? Give examples of commonly used Artisan commands.

Artisan is the command-line interface (CLI) tool included with Laravel. It helps developers perform repetitive tasks quickly without manually editing files. Artisan is built on top of the Symfony Console component, which makes it powerful and easy to use.

You can run Artisan commands using:

php artisan command-name


Examples of Commonly Used Artisan Commands

1. Start the Development Server

php artisan serve

This command starts Laravel's built-in local development server.
Default URL: http://127.0.0.1:8000


2. Create a Controller

php artisan make:controller UserController

Creates a new controller named UserController in the app/Http/Controllers directory.


3. Create a Model

php artisan make:model Product

Generates a Product model in the app/Models directory.


4. Create a Migration

php artisan make:migration create_products_table

Creates a new migration file for the products table in the database/migrations folder.


5. Run Migrations

php artisan migrate

Executes all pending migration files to update the database schema.


6. Clear Cache

php artisan cache:clear

Clears the application cache.


7. Generate Application Key

php artisan key:generate

Generates a new application encryption key and updates the .env file.


8. View Route List

php artisan route:list

Displays all registered routes with their HTTP methods, URIs, and assigned controllers.


Benefits of Using Artisan

  • Faster development – automate repetitive tasks.
  • Standardized code – follow Laravel conventions.
  • Powerful utilities – work with migrations, routes, and caching easily.


In short: Artisan is your best friend in Laravel development. Mastering Artisan commands can make you a much more efficient Laravel developer.


Comments