Skip to content

Commit

Permalink
快速生成 jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
liyu001989 committed Aug 6, 2020
1 parent 6463535 commit 7b2e3cb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/Console/Commands/GenerateToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Console\Commands;

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

class GenerateToken extends Command
{
protected $signature = 'larabbs:generate-token';

protected $description = '快速为用户生成 token';

public function __construct()
{
parent::__construct();
}

public function handle()
{
$userId = $this->ask('输入用户 id');

$user = User::find($userId);

if (!$user) {
$this->error('用户不存在');
}

// 一年以后过期
$ttl = 365*24*60;
$this->info(auth('api')->setTTL($ttl)->login($user));
}
}

0 comments on commit 7b2e3cb

Please sign in to comment.