Files
crawlshot/app/Console/Commands/CreateApiToken.php
2025-08-10 21:10:33 +08:00

31 lines
858 B
PHP

<?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;
}
}