56 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Models\CV;
use Illuminate\Console\Command;
class CVInfo extends Command
{
protected $signature = 'cv:info {id}';
protected $description = 'Show info about CV';
public function handle(): int
{
if (! ($cv = CV::find($id = $this->argument('id')))) {
$this->error('CV not found!');
return Command::FAILURE;
}
$this->line('ID: '. $cv->id);
$this->line('Token: '. $cv->token);
$this->line('Company: '. $cv->recipient);
$this->line('Phone: '. $cv->formattedPhoneNumber .', '. $cv->PhoneNumber);
$this->line('Locations: '. implode(' / ', $cv->locations));
$this->line('Actual views: '. $cv->info()->select('id')->get()->count());
$this->line('Registered views: '. $cv->views);
$this->line('Mission: '. (is_null($mission = $cv->mission) ? 'domyślne' : $mission));
$this->line('Rodo: '. (is_null($rodo = $cv->rodo) ? 'domyślne' : $rodo));
$this->line('');
$this->line('Showed list:');
$listCVInfo = [];
foreach (($cvInfoList = $cv->info()->orderByDesc('id')->get(['id', 'ip', 'created_at'])) as $cvInfo) {
$listCVInfo[] = [
'id' => $cvInfo->id,
'ip' => $cvInfo->ip,
'created' => $cvInfo->created_at->format('d-m-Y H:i:s'),
];
}
if ($cvInfoList->count() === 0)
$this->warn('Empty!');
else
$this->table(
['Id', 'IP', 'Showed'],
$listCVInfo,
);
return Command::SUCCESS;
}
}