6
0
Fork 0
jiqu-library-server/app/Console/Commands/UserToken.php

53 lines
1.0 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\User;
class UserToken extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:token {id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '生成用户的登录授权码';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$user = User::findOrFail($this->argument('id'));
$tokens = $user->tokens;
$token = '';
if ($tokens->count() > 0) {
$token = $tokens->first();
} else {
$token = $user->createToken('command');
}
$this->info($token->plainTextToken);
return 0;
}
}