Introduction
This tutorial walks you through building a Laravel application with custom artisan commands usingrevolution/laravel-console-starter. This starter kit accelerates development of applications that primarily use artisan commands, leveraging the full Laravel framework ecosystem rather than building standalone CLI tools.
Benefits of using revolution/laravel-console-starter:
- Quick Setup — Start developing console applications immediately without complex configurations
- Laravel Ecosystem — Use Laravel’s rich features (task scheduling, database, notifications, etc.) in your console app
- Artisan Commands — Leverage Laravel’s powerful Artisan system to easily create and manage your own commands
- Testability — Write tests for your console commands using Laravel’s testing framework
Prerequisites
Ensure the following software is installed before you begin.- PHP
^8.3 - Composer (https://getcomposer.org/)
- Laravel Installer (
composer global require laravel/installer)
Project Setup
Create a new project
my-app directory and sets up the basic console application structure.The following happen automatically during installation:- An
.envfile is generated from.env.example php artisan key:generatesets the application encryption key
Review the environment configuration
MAIL_MAILER=log).If you need to send actual emails, configure a service like Mailgun, Postmark, or SES in your .env file.Creating a Console Command
Generate a command
make:command Artisan command to create a new command:YourCommandName— The class name of the command (e.g.,SendDailyReport)your:command— The command name used to call it (e.g.,report:send-daily)
app/Console/Commands/YourCommandName.php.Implement the command
$signature property defines how the command is called. Write your logic in the handle() method.Run the command
storage/logs/laravel.log and the console.Task Scheduling with GitHub Actions
Use GitHub Actions to run commands on a regular schedule — no server cron jobs required.Review the workflow file
.github/workflows/cron.yml:Change the command
php artisan inspire with your own command:Adjust the schedule
cron expression to set your desired frequency:Handle sensitive information with secrets
Notification Feature
You can notify yourself of command results or errors via email, Slack, and other channels.Create a notification class
app/Notifications/TaskCompleted.php.Configure notification channels
Send a notification from your command
Practical Application Examples
Example 1: Website Uptime Monitoring with Slack Alerts
Create a command that checks if your websites are online and sends Slack alerts when issues are detected.Install the Slack notification channel
Create the command and notification
Configure Slack
.env:config/services.php:Implement the notification
app/Notifications/WebsiteDown.php:Implement the command
app/Console/Commands/MonitorWebsites.php:Schedule in GitHub Actions
.github/workflows/cron.yml:Example 2: Cryptocurrency Portfolio Update with Discord Notifications
Fetch cryptocurrency prices from the CoinGecko API and send portfolio updates to Discord via webhook.Install the Discord notification channel
Create the command and notification
Configure Discord
.env:config/services.php:Implement and run the command
Example 3: Website Content Scraping with Email Notification
Create a command that scrapes content from a website and sends the results via email.Create the command and notification
Configure mail
.env with mail settings:Implement and run the command
Next Steps
You now know the fundamentals of building Laravel console applications withrevolution/laravel-console-starter.
To continue your journey:
- Explore Laravel’s documentation — Dive deeper into features that can enhance your console applications at laravel.com/docs
- Implement testing — Write tests for your commands using Laravel’s testing framework to ensure reliability
- Explore package development — Package your console commands as reusable Laravel packages if you create similar functionality across projects
- Stay updated — Follow Laravel News and the official Laravel blog to stay current with best practices