Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a Laravel command in a subfolder?

Tags:

php

laravel-5

So I'm trying to create a custom console command in Laravel 5.1 which does some helpful function for my project. I can do this fine when putting the console command in a file located at the base commands folder but not when I just to add a subdirectory.

'App\Console\Commands\SomeCustomCommandThatWorks',
'App\Console\Commands\MySubNameSpace\CustomCommandThatFails',

So how do I add my command like MySubNameSpace\Command?

Namespace doesn't appear to have any effect on this. The namespace of the command could be App\Console\MySubNameSpace\MyCommand or App\Console\MyCommand both fail if the file is located at 'App\Console\Commands\MySubNameSpace\MyCommand'. The file also fails if located at 'App\Console\Commands\MyCommand' with namespace App\Console\MySubNameSpace\MyCommand.

Right now I get this error.

Class App\Console\Commands\DeletePhantomServers does not exist

I have tried running composer dumpautoload but to no success.

Any help would be appreciated. enter image description here

like image 406
James Avatar asked Jul 31 '15 19:07

James


1 Answers

According to autoloading standards, none of the combinations you have above will work. The namespace needs to be set according to the directory. So if you have the command in this folder

Console\Commands\MySubNameSpace\MyCommand

your namespace has to be

App\Console\Commands\MySubNameSpace\MyCommand
like image 119
baao Avatar answered Oct 13 '22 11:10

baao