laravel 创建命令|artisan 获取 token
2018年11月12日1.创建命令文件
1 |
$ php artisan make:command GetToken |
2开始编辑app/Console/Commands/GetToken.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php namespace App\Console\Commands; use App\Models\User; use Illuminate\Console\Command; class GetToken extends Command { protected $signature = 'api:get-token'; #命令名字 protected $description = '快速为用户生成 token'; #简介 public function __construct() { parent::__construct(); } public function handle() { $userId = $this->ask('输入用户 id'); #让用户输入东西 $user = User::find($userId); if (!$user) { return $this->error('用户不存在'); } $ttl = 365 * 24 * 60; #过期时间 $this->info(\Auth::guard('api')->setTTL($ttl)->fromUser($user)); } } |
3.测试命令