ifnex/04_Laravel/app/Console/Commands/GenerateApiToken.php
Kazem Alghasi 78f5919b69 feat(wallet): complete wallet system with admin adjust, freeze/unfreeze, activity logs
- Add Enums: TransactionType, TransactionStatus, PaymentGateway
- Migrations: wallets, wallet_transactions, wallet_activity_logs
- Models: Wallet, WalletTransaction, WalletActivityLog
- Services: WalletService with complete business logic
- Controllers: WalletController, PaymentController
- Filament Resources: WalletResource, WalletTransactionResource
- Artisan Command: ifnex:token for API token generation
- Sanctum integration with statefulApi and exception handling
- Full API endpoints: balance, transactions, admin-adjust, freeze/unfreeze
2026-08-07 22:51:42 +03:30

57 lines
1.9 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class GenerateApiToken extends Command
{
protected $signature = 'ifnex:token
{--email=admin@ifnex.local : ایمیل کاربر}
{--name=test-token : نام توکن}';
protected $description = 'ساخت توکن API برای تست';
public function handle()
{
$email = $this->option('email');
$tokenName = $this->option('name');
$user = User::where('email', $email)->first();
if (!$user) {
$this->error("کاربر با ایمیل '{$email}' یافت نشد!");
$this->info('کاربران موجود:');
User::all(['id', 'name', 'email', 'role'])->each(function ($u) {
$this->line(" - ID: {$u->id} | {$u->name} | {$u->email} | {$u->role->value}");
});
return 1;
}
// پاک کردن توکن‌های قبلی
$oldCount = $user->tokens()->count();
$user->tokens()->delete();
$this->info("{$oldCount} توکن قدیمی پاک شد.");
// ساخت توکن جدید
$token = $user->createToken($tokenName)->plainTextToken;
$this->newLine();
$this->line('========================================');
$this->info('توکن جدید (این را کپی کنید):');
$this->line('========================================');
$this->newLine();
$this->line($token);
$this->newLine();
$this->line('========================================');
$this->newLine();
$this->info("اطلاعات کاربر:");
$this->line(" ID: {$user->id}");
$this->line(" Name: {$user->name}");
$this->line(" Email: {$user->email}");
$this->line(" Role: {$user->role->value}");
return 0;
}
}