6
0
Fork 0

command user:token

release
panliang 2022-05-13 13:29:09 +08:00
parent 74e3550ac8
commit 9772dc4e12
1 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,52 @@
<?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;
}
}