Update
This commit is contained in:
31
app/Console/Commands/CreateApiToken.php
Normal file
31
app/Console/Commands/CreateApiToken.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CreateApiToken extends Command
|
||||
{
|
||||
protected $signature = 'crawlshot:create-token {name=API User} {email=api@crawlshot.test}';
|
||||
protected $description = 'Create an API token for Crawlshot';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$name = $this->argument('name');
|
||||
$email = $this->argument('email');
|
||||
|
||||
$user = User::firstOrCreate(['email' => $email], [
|
||||
'name' => $name,
|
||||
'password' => bcrypt('password')
|
||||
]);
|
||||
|
||||
$token = $user->createToken('crawlshot-api')->plainTextToken;
|
||||
|
||||
$this->info("API Token created successfully!");
|
||||
$this->line("Token: {$token}");
|
||||
$this->line("Use this in your Authorization header: Bearer {$token}");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user