Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 40 of the Laravel Fundamentals: From Zero to Your First App course
LaravelJune 25, 20263 min read

Introduction to Artisan Commands: Your CLI Power Tool

Master the Artisan CLI to automate repetitive tasks and debug your Laravel application. Learn how to list, create, and run custom commands today.

LaravelArtisanCLIAutomationPHPDevelopment Toolsbackend

Previously in this course, we explored Task Manager: Adding Status and Priorities in Laravel, where we evolved our database schema to handle more complex data. Now, we shift our focus from the browser to the terminal, where you'll learn to harness the full power of Artisan to speed up your development workflow.

What is Artisan?

Artisan is the command-line interface (CLI) included with Laravel. It provides a number of helpful commands for your application, ranging from scaffolding code to managing database migrations and clearing caches. Think of it as your primary bridge between your code and the underlying framework.

When you run php artisan in your project root, you aren't just running a script; you are interacting with a sophisticated tool designed to handle the "heavy lifting" of application management.

Listing and Using Commands

To see everything Artisan can do, open your terminal in your project directory and run:

Bash
php artisan

You will see a list of commands categorized by their function. Common ones you’ve already used include make:migration or make:controller. If you ever need to know the specific options for a command, you can use the help flag:

Bash
php artisan help make:controller

This is your go-to reference whenever you forget the exact syntax of a flag or argument.

Creating Custom Commands for Automation

While built-in commands are powerful, you will eventually reach a point where you need to perform custom tasks—like cleaning up old tasks in our Task Manager app or sending a daily summary email. Artisan makes this easy.

To create a custom command, run the following:

Bash
php artisan make:command CleanupOldTasks

This generates a file in app/Console/Commands. Open that file, and you'll see a $signature property. This is what you type into the CLI to trigger your code.

PHP
protected $signature = 'tasks:cleanup';

public function handle()
{
    $count = \App\Models\Task::where('created_at', '<', now()->subDays(30))->delete();
    $this->info("Deleted {$count} old tasks.");
}

In this example, we’ve created a command that deletes tasks older than 30 days. The handle() method contains the logic that runs when you execute php artisan tasks:cleanup. For more advanced implementations, refer to Laravel Artisan Custom Commands: Automate Tasks Like a Pro and Mastering Laravel Artisan Command Development for CLI Tools.

Debugging with Tinker

Sometimes, you don't want to write a full command or a controller method just to test a small snippet of code. This is where php artisan tinker shines.

Tinker is a REPL (Read-Eval-Print Loop) for your Laravel application. It allows you to interact with your database and application logic in real-time.

  1. Run php artisan tinker.
  2. Try creating a new task:
    PHP
    \App\Models\Task::create(['title' => 'Tinker Test', 'user_id' => 1]);
  3. Query it back:
    PHP
    \App\Models\Task::all();

It’s an incredibly fast way to verify your Introduction to Database Relationships in Laravel or debug why a query isn't returning what you expect.

Hands-on Exercise

For our Task Manager project, create a custom command called tasks:status-report that prints the total number of tasks currently in the database to the terminal. Use $this->info() to output the result. Once finished, run it and verify the count matches your database expectations.

Common Pitfalls

  • Forgetting to Register: In older versions of Laravel, you had to manually register commands. In modern Laravel, the framework auto-discovers them in the app/Console/Commands folder. If your command isn't showing up, ensure the file is in that directory and the namespace is correct.
  • Over-complicating handle(): Keep your logic inside handle() thin. If your command does something complex, extract that logic into a service class.
  • Tinker State: Remember that Tinker keeps your application state in memory. If you change a file on disk, you may need to exit and restart Tinker (exit or Ctrl+C) for the changes to take effect.

Recap

Artisan is more than just a list of commands; it is the engine of your development environment. By leveraging CLI automation, you minimize manual errors and speed up your workflow. You now know how to list commands, build your own, and use Tinker to inspect your application's state on the fly.

Up next: We will dive deeper into the power of the REPL in "Debugging with Laravel Tinker."

Previous lessonTask Manager: Adding Status and PrioritiesNext lesson Debugging with Laravel Tinker
Back to Blog

Similar Posts

LaravelPHPJune 23, 20263 min read

Mastering Laravel Artisan Command Development for CLI Tools

Mastering a Laravel artisan command allows you to automate repetitive tasks. Learn how to build custom CLI tools with clear console output for your projects.

Read more
LaravelPHPJune 21, 2026

Part of the course

Laravel Fundamentals: From Zero to Your First App

beginner · Lesson 40 of 52

  1. 1

    Setting Up the Local Development Environment

    4 min
  2. 2

    Installing Laravel and Exploring Directory Structure

    3 min
  3. 3

    Understanding the .env File and Configuration

    3 min
4 min read

Laravel Artisan Custom Commands: Automate Tasks Like a Pro

Laravel Artisan custom console commands help you automate repetitive tasks easily. Learn to build your own CLI tools to boost your development productivity.

Read more
LaravelJune 25, 20263 min read

Debugging with Laravel Tinker: A Practical Guide

Stop refreshing your browser to test code. Learn how to use Laravel Tinker to run Eloquent queries and debug your application logic directly in the terminal.

Read more
  • 4

    The Laravel Application Lifecycle

    4 min
  • 5

    Initializing the Task Manager Project

    3 min
  • 6

    Defining Basic Web Routes

    4 min
  • 7

    Using Route Parameters

    3 min
  • 8

    Creating Your First Controller

    3 min
  • 9

    Returning Responses and Redirects

    3 min
  • 10

    Task Manager: Implementing the Task List Route

    3 min
  • 11

    Introduction to Blade Templating

    3 min
  • 12

    Using Blade Layouts and Sections

    3 min
  • 13

    Implementing Blade Partials

    4 min
  • 14

    Mastering Blade Directives for Loops and Conditionals

    3 min
  • 15

    Task Manager: Building the User Interface

    3 min
  • 16

    Understanding Database Migrations

    3 min
  • 17

    Working with Eloquent Models

    3 min
  • 18

    Performing Basic CRUD Operations

    3 min
  • 19

    Seeding the Database

    3 min
  • 20

    Task Manager: Displaying Real Database Records

    3 min
  • 21

    Capturing User Input from Forms

    4 min
  • 22

    Introduction to Laravel Validation

    3 min
  • 23

    Customizing Validation Error Messages

    3 min
  • 24

    Using Form Requests for Validation

    3 min
  • 25

    Introduction to Authentication

    4 min
  • 26

    Protecting Routes with Middleware

    3 min
  • 27

    Understanding CSRF Protection

    3 min
  • 28

    Preventing Mass Assignment

    3 min
  • 29

    Task Manager: Securing the Application

    3 min
  • 30

    Introduction to Route Model Binding

    3 min
  • 31

    Updating Existing Records

    3 min
  • 32

    Deleting Records

    3 min
  • 33

    Using Named Routes

    3 min
  • 34

    Task Manager: Completing CRUD Functionality

    3 min
  • 35

    Introduction to Database Relationships

    3 min
  • 36

    Querying Related Data

    4 min
  • 37

    Handling File Uploads

    3 min
  • 38

    Using Flash Messages for User Feedback

    3 min
  • 39

    Task Manager: Adding Status and Priorities

    3 min
  • 40

    Introduction to Artisan Commands

    3 min
  • 41

    Debugging with Laravel Tinker

    3 min
  • 42

    Understanding Service Providers

    4 min
  • 43

    Using View Composers

    3 min
  • 44

    Task Manager: Refactoring for Clean Code

    Coming soon
  • 45

    Introduction to Testing

    Coming soon
  • 46

    Testing Forms and Validation

    Coming soon
  • 47

    Using Database Transactions

    Coming soon
  • 48

    Handling Global Exceptions

    Coming soon
  • 49

    Preparing for Production

    Coming soon
  • 50

    Environment Security Best Practices

    Coming soon
  • 51

    Managing Assets in Production

    Coming soon
  • 52

    Task Manager: Deployment Preparation

    Coming soon
  • View full course