当我运行php artisan token时找不到类:在laravel中生成1,这样我就可以获得Swagger UI Auth的不记名令牌

问题描述

<?PHP

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\User;

class TokenCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'token:generate {id}';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $id = $this->argument('id');
        $user = User::find($id);

        \Auth::setUser($user);

        $console = new ConsoleOutput();

        $console->writeln($user->createtoken('admin')->accesstoken);
    }
}

我试图在Swagger UI中获取用户详细信息,但是当我运行“ PHP artisan token:generate 1”以在swagger UI中生成用于授权的令牌时,出现错误

我是laravel的新手,这是我遇到的错误

找不到“ App \ Console \ Commands \ ConsoleOutput”类

在C:\ xampp \ htdocs \ Event \ ems \ backend \ app \ Console \ Commands \ TokenCommand.PHP:29 25▕$ user =用户:: find($ id); 26▕ 27▕\ Auth :: setUser($ user); 28▕ ➜29▕$ console = new ConsoleOutput(); 30▕ 31▕$ console-> writeln($ user-> createtoken('admin')-> accesstoken); 32▕} 33▕}

1 C:\ xampp \ htdocs \ Event \ ems \ backend \ vendor \ laravel \ framework \ src \ Illuminate \ Container \ BoundMethod.PHP:36 App \ Console \ Commands \ TokenCommand :: handle()

2 C:\ xampp \ htdocs \ Event \ ems \ backend \ vendor \ laravel \ framework \ src \ Illuminate \ Container \ Util.PHP:40 Illuminate \ Container \ BoundMethod :: Illuminate \ Container {closure}()

解决方法

您尚未导入ConsoleOutput类。将以下行添加到类文件的顶部。

use Symfony\Component\Console\Output\ConsoleOutput;