Laravel 我不能在拉威尔执行我的命令

Laravel 我不能在拉威尔执行我的命令,laravel,command,Laravel,Command,我在laravel中创建了一个命令,当我执行它时,我发现了这个错误 php artisan query:all ReflectionException : Class App\Services\QueryService does not exist ... 我为呼叫服务编写的代码是 <?php namespace App\Console\Commands; use App\Services\QueryService; use Illuminate\Console\Command;

我在laravel中创建了一个命令,当我执行它时,我发现了这个错误

php artisan query:all

ReflectionException  : Class App\Services\QueryService does not exist
...
我为呼叫服务编写的代码是

<?php

namespace App\Console\Commands;

use App\Services\QueryService;
use Illuminate\Console\Command;

class QueryUnits extends Command
{
    protected $signature = 'query:all';
    protected $description = 'Command description';
    protected $queryService;
    public function __construct(QueryService $queryService)
    {
        $this->queryService = $queryService;
        parent::__construct();
    }
    public function handle()
    {
        $this->info('Query started ...');
        try{
            $this->queryService->queryAll();
        } catch (\Exception $exception){
            $this->error($exception->getMessage());
            return 1;
        }
        $this->info('Query successful');
    }
}

如果如您所说存在
App\Services\QueryService
,则有时会因为配置缓存而出现问题。 因此,您需要执行清除配置缓存

php artisan config:clear

这是QueryService代码

<?php
namespace App\Services;
use App\services\WialonAllUnits;
class QueryService{
        protected $wialonAllUnits;
        public function __construct(
            WialonAllUnits $wialonAllUnits
        )
        {
            $this->wialonAllUnits = $wialonAllUnits;
        }
        public function queryAll(){
            $this->wialonAllUnits->query('af56b938eaf39d332a244913fc831d4b84F6FFA3563A3E2A3C2026BAE4EEFC33653744ED');
        }
    }

您在
Console\Handler.php
中注册了它吗?您是否尝试过
composer dump autoload-o

您的WialonalUnits类中存在语法错误。您有一个错误的字符串连接运算符。请确保将
{“token”:“+$apiKey+”}
更改为
{“token”:“.$apiKey.”“}

是否可以检查
App\Services\QueryService
是否存在??在Laravel项目目录中。是的,我确信它存在,但您的
QueryService
code?
<?php
    namespace App\services;
    use App\Models\all_unit;
    use Carbon\Carbon;
    use GuzzleHttp\Client;
    use Illuminate\Support\Collection;
    class WialonAllUnits{
        public function query(string $apiKey) : Collection {
            $result = collect('aa','sdsd'); //create collect variable to return data in it
            $guzzleClient = new Client([ //create quzzle Client
                'base_uri' => 'http://track.myserver.com/wialon/ajax.html'
            ]);
                $response = $guzzleClient->get('v1/current.json',[
                    'query' =>[
                        'svc' =>'token/login',
                        'params' =>'{"token":"'+$apiKey+'"}',
                    ]
                ]);
                $response = json_decode($response->getBody()->getContents(), true); //create json from $response
                $allUnits = new all_unit(); //create weatherStatus object
                //adding prameters
                $allUnits->unitName()->$response[0];
                //save prameters
                $allUnits->save();
                //push each status to the result to return data later
                $result->push($allUnits);

            //return all result after go outside the loop
            return $result;
        }
    }