#Moving commands to different directory?

18 messages · Page 1 of 1 (latest)

acoustic monolith
#

I moved a command to a new directory in laravel, since doing this I cant seem to run the command.

workspace/project/app/Dealer

<?php

namespace App\Dealer\Commands;

use Illuminate\Console\Command;

class FindPotentialMatches extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'dealer:find-potential-matches';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Find potential matches';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        dump('hi'); die;
        //
    }
}

$ php artisan dealer:find-potential-matches

ERROR There are no commands defined in the "app" namespace.

pale ore
acoustic monolith
#

I assume like this

    FindPotentialMatches::class
];```
#

Inside Kernel.php?

pale ore
#

Yes.

#

Or alternatively, create and register a service provider if you’re moving the command because you want to put it in some sort of “package” or “module”.

acoustic monolith
#

Okay, thank you Martin

acoustic monolith
#

still having bother with this

#

  Target class [FindPotentialFCAMatches] does not exist.

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:916
    912▕ 
    913▕         try {
    914▕             $reflector = new ReflectionClass($concrete);
    915▕         } catch (ReflectionException $e) {
  ➜ 916▕             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
    917▕         }
    918▕ 
    919▕         // If the type is not instantiable, the developer is attempting to resolve
    920▕         // an abstract type such as an Interface or Abstract Class and there is

      +10 vendor frames 

  11  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#

namespace App\Console;

use FindPotentialFCAMatches;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{

    protected $commands = [
        FindPotentialFCAMatches::class
    ];
#

I changed it to this @pale ore


namespace App\Console;

use App\Dealer\Commands\FindPotentialFCAMatches;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{

    protected $commands = [
        FindPotentialFCAMatches::class
    ];

and i now get

  Cannot declare class FindPotentialFCAMatches, because the name is already in use

  at app/Dealer/Commands/FindPotentialFCAMatches.php:7
      3▕ use App\API\FCA\Client;
      4▕ use App\Jobs\SearchPotentialFCAMatches;
      5▕ use Illuminate\Console\Command;
      6▕ 
  ➜   7▕ class FindPotentialFCAMatches extends Command
      8▕ {
      9▕     protected $signature = 'dealer:find-potential-fca-matches';
     10▕ 
     11▕     protected $description = 'Find potential FCA matches for dealers';

      +1 vendor frames 

pale ore
#

@acoustic monolith Your namespace looks completely wrong. Why are you moving stuff around?

#

This is wrong:

use FindPotentialFCAMatches;

Your namespace of App\Console is wrong if your class is actually at app/Dealer/Commands/FindPotentialFCAMatches.php

acoustic monolith
#

I thought namespace App\Console was necessary for Kernel.php

#

When I remove App\Console

pale ore
#

Your namespace needs to follow the directory structure.

#

I’d suggest not moving files around if you’re not actually comfortable with how namespaces work or the PSR-4 standard.

acoustic monolith
#

Okay ill read up on it thank you