Skip to main content
Tutorial Free

Want an inspirational quote? There's Artisan command for that!

December 29, 2016
2 min read

Web-development is not all serious - there are some fun activities too. So let's have a break from mega-urgent code writing and get some inspiration. From our beloved Artisan - with a command "inspire".

It's not officially documented, but if you run php artisan inspire, you will get a random motivational quote right in your terminal. Like this.

screen-shot-2016-12-29-at-12-11-04-pm

How does it work? Well, if you ever looked at /routes folder, there are three files there:

  • web.php - the one we generally use
  • api.php - for projects with API
  • console.php - this one is interesting for us now!

Let's take a look at routes/console.php:

use Illuminate\Foundation\Inspiring;

/*
|--------------------------------------------------------------------------
| Console Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of your Closure based console
| commands. Each Closure is bound to a command instance allowing a
| simple approach to interacting with each command's IO methods.
|
*/

Artisan::command('inspire', function () {
    $this->comment(Inspiring::quote());
});

This is where we find that inspire command, and actually - the whole console.php file concept, which is not documented properly, is about routing your artisan commands like this, instead of going through app/Console/Kernel.php.

Is it really usable? Good question, since it's not really documented - I guess, Taylor didn't pay too much attention to it (maybe in the future?), so for now it's just a cool little thing to know.

I hope it inspires you for the upcoming 2017!

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.