Artisan is the command line tool used in Laravel framework. It offers a bunch of useful command that can help you develop application quickly. Apart from Artisan available commands, you can create your own custom commands to improve your workflow. Artisan is driven by the powerful Symfony Console component.
If you have not installed laravel check my previous post on
How to Install Laravel 4 Framework
What is Composer and How to Manage Package Dependency through Composer
Laravel Artisan Available Commands
Let’s first check the artisan available commands. To check the available artisan command just type.
1 |
php artisan |
OR
1 |
php artisan list |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
Laravel Framework version 4.1.9 Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version -V Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction -n Do not ask any interactive question. --env The environment the command should run under. Available commands: <strong>changes</strong> Display the framework change list <strong>clear-compiled</strong> Remove the compiled class file <strong>down</strong> Put the application into maintenance mode <strong>dump-autoload</strong> Regenerate framework autoload files <strong>env</strong> Display the current framework environment <strong>help</strong> Displays help for a command <strong>list</strong> Lists commands <strong>migrate</strong> Run the database migrations <strong>optimize</strong> Optimize the framework for better performance <strong>routes</strong> List all registered routes <strong>serve</strong> Serve the application on the PHP development server <strong>tail</strong> Tail a log file on a remote server <strong>tinker</strong> Interact with your application <strong>up</strong> Bring the application out of maintenance mode <strong>workbench</strong> Create a new package workbench <strong>asset</strong> asset:publish Publish a package's assets to the public directory <strong>auth</strong> auth:clear-reminders Flush expired reminders. auth:reminders Create a migration for the password reminders table auth:reminders-controller Create a stub password reminder controller <strong>cache</strong> cache:clear Flush the application cache <strong>command</strong> command:make Create a new Artisan command <strong>config</strong> config:publish Publish a package's configuration to the application <strong>controller</strong> controller:make Create a new resourceful controller <strong>db</strong> db:seed Seed the database with records <strong>key</strong> key:generate Set the application key <strong>migrate</strong> migrate:install Create the migration repository migrate:make Create a new migration file migrate:refresh Reset and re-run all migrations migrate:reset Rollback all database migrations migrate:rollback Rollback the last database migration <strong>queue</strong> queue:failed List all of the failed queue jobs queue:failed-table Create a migration for the failed queue jobs database table queue:flush Flush all of the failed queue jobs queue:forget Delete a failed queue job queue:listen Listen to a given queue queue:retry Retry a failed queue job queue:subscribe Subscribe a URL to an Iron.io push queue queue:work Process the next job on a queue <strong>session</strong> session:table Create a migration for the session database table <strong>view</strong> view:publish Publish a package's views to the application |
Apart from using the available commands you can create your own commands.
How to Create New Artisan Custom Command
To create a new php artisan command. Type following
1 |
php artisan command:make firstcommand |
firstcommand is the name of command.
To define this command go to
1 |
/app/commands/firstcommand.php |
Open this file and define command functionality in fire method. So whenever this command is executed fire method is called.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; class firstcommand extends Command { /** * The console command name. * * @var string */ protected $name = 'command:name'; /** * The console command description. * * @var string */ protected $description = 'Command description.'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function fire() { // } /** * Get the console command arguments. * * @return array */ protected function getArguments() { return array( array('example', InputArgument::REQUIRED, 'An example argument.'), ); } /** * Get the console command options. * * @return array */ protected function getOptions() { return array( array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null), ); } } |
To make sure artisan know the newly created command Add the following line to your app/start/artisan.php file.
1 |
Artisan::add(new TestCommand); |
Conclusion
This is just an overview of available Artisan commands and how to create custom commands. In my next posts, i’ll explain how to create applications in Laravel framework and how artisan command help you to develop application quickly.