Laravel - Artisan


How can we use artisan?

php artisan list
php artisan help migrate

How can we add a new artisan command?

php artisan make:console LogDemo  --command=log:demo

Open the LogDemo.php class under app->Console->Commands to provide the description and the implementation of the handle method.

Modify the Kernel.php to register the command:

protected $commands = [

Where does artisan come from?

In Laravel 3, Artisan was written from scratch by Taylor Otwell (Laravel's creator), thus it was quite basic (although still awesome). Now that Laravel 4 is Composer based, it can use existing packages developed by other brilliant developers. As a result, Laravel 4 now depends on numerous packages from the Symfony framework. One of these such packages is the excellent Console Component.

If we take a look at the source of the Artisan application at Illuminate\Console\Application, we can see that the class, itself, extends Symfony\Component\Console\Application. This is where Artisan draws its power. Although Artisan makes use of Symfony's Console component, a lot of the common methods have been given more fluent Laravel-like aliases. So don't worry, it'll still feel like you're developing with Laravel!

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License