Oh boy, if you’re just starting out with Laravel, you’ve probably heard about the magical Artisan commands. But what are they, and why should you use them? Let’s get to it!
Artisan, natch, is Laravel’s built-in command-line interface (CLI). It’s a crucial tool that comes with the framework and offers you a wide range of features to streamline your development process. Here’s a quick rundown of some of the most useful commands for beginners:
1. Check Available Commands
Before diving in, it’s essential to understand the available commands in your Laravel project. The php artisan list
command displays all the commands in your project, including their names and brief descriptions:
php artisan list
```
List of available commands:
- php artisan
- The main Laravel CLI command
- php artisan make:controller
- Generates a new controller file in the 'app/Http/Controllers' directory
- php artisan make:model
- GeneratesIf you’ve just started learning Laravel, you’ve probably heard about Artisan commands.
But what exactly are they? And why should you use them?
In this guide, we’ll walk through the basics of Artisan, some commonly used commands, and why they make Laravel development so much easier.
What is Artisan?
Artisan is Laravel’s built-in command-line interface (CLI).
It comes bundled with the framework and allows you to:
- Generate code quickly (controllers, models, migrations, etc.)
- Run database migrations
- Start a development server
- Clear caches and optimize your app
- And much more...
Think of Artisan as your personal assistant that takes care of repetitive coding tasks so you can focus on building features.
Basic Artisan Commands You Should Know
Here are some of the most useful commands for beginners:
1. Check Available Commands
php artisan list
This will display all the available Artisan commands in your project.
2. Check Laravel Version
php artisan --version
Quick way to see which Laravel version your project is running on.
3. Create a Controller
php artisan make:controller UserController
This generates a new UserController.php
file inside the app/Http/Controllers
directory.
4. Create a Model
php artisan make:model Post
This creates a Post.php
model inside the app/Models
directory.
5. Run Migrations
php artisan migrate
Applies all pending migrations to your database.
6. Rollback Migrations
php artisan migrate:rollback
Undoes the last batch of migrations. Useful when testing database changes.
7. Start Local Development Server
php artisan serve
Runs a local PHP server so you can test your app in the browser. By default, it’s available at:
👉 http://127.0.0.1:8000
Why Use Artisan?
-
Saves time – You don’t have to write boilerplate code manually.
-
Reduces errors – Commands follow Laravel’s conventions.
-
Boosts productivity – Quick shortcuts for everyday tasks.
-
Keeps project organized – Files are generated in the right structure.
Pro Tips for Beginners
- Use
php artisan help <command>
to get details about any command. Example:
php artisan help make:controller
- Explore Artisan daily. The more commands you try, the faster you’ll learn Laravel.
Final Thoughts
Artisan is one of the features that makes Laravel such a developer-friendly framework.
If you’re just getting started, make it a habit to run a few Artisan commands every day. You’ll quickly see how much time it saves and how it improves your workflow.
👉 What’s your favorite Artisan command so far? Share it in the comments!