GLOB
Montagne, Informatique & Pensées...

Command "dump-autoload" is not defined

publié le 04/11/2015

In order to optimize the way I develop, I recently started writing artisan commands. It is a very good way to accelerate a lot of procedure that were mostly based on copy/paste/replace.

Today I stumbled upon a small problem, I wanted to dump-autoload after some files got created. According to the documentation all you have to do is :

\Artisan::call('dump-autoload')

Except that it seems that dump-autoload can't be called this way. After some search over the Internet, It seems I'm not the only one that has this problem but nobody had a solution other than using exec (gloups ...). Looking for an answer I greped the vendor directory in search for references of dump-autoload or dumpAutoload. I found an interesting one in laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php on line 81.

The solution is simple inject Composer in your command

    public function __construct(Composer $composer)
    {
        parent::__construct();
        $this->composer = $composer;
    }

Then call the dumpAutoloads method of composer :

	$this->composer->dumpAutoloads();

That will do the trick.


laravel-4/5 artisan dump-autoload

Pourquoi un blog ?

Il me fallait bien entrer dans la modernité, après tout, un développeur sans blog, c'est comme un trailer sans pipette ça fait pas sérieux.

Je ne suis pas sûr que ce blog fera sérieux mais, si lecteur il y a, ce sera à eux d'en décider.


Powered by Jalmot