- add cv info
This commit is contained in:
parent
390c5b8087
commit
d35421a97e
42
app/Console/Commands/CVInfo.php
Normal file
42
app/Console/Commands/CVInfo.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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('Views: '. $cv->views);
|
||||
$this->line('');
|
||||
|
||||
$this->line('Showed list:');
|
||||
foreach ($cv->info()->orderByDesc('id')->get() as $cvInfo) {
|
||||
$this->line('ID: '. $cvInfo->id);
|
||||
$this->line('IP: '. $cvInfo->ip);
|
||||
$this->line('Date: '. $cvInfo->created_at->format('d-m-Y H:i:s'));
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
@ -13,6 +13,10 @@ class CVController extends Controller
|
||||
{
|
||||
public function show(CV $cv): JsonResource
|
||||
{
|
||||
$cv->info()
|
||||
->create([
|
||||
'ip' => $_SERVER['REMOTE_ADDR'],
|
||||
]);
|
||||
$cv->update(['views' => $cv->views+=1]);
|
||||
|
||||
return new CVResource($cv);
|
||||
|
@ -7,6 +7,8 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@ -42,6 +44,11 @@ class CV extends Model
|
||||
);
|
||||
}
|
||||
|
||||
public function info(): HasMany
|
||||
{
|
||||
return $this->hasMany(CVInfo::class, 'cv_id');
|
||||
}
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'token';
|
||||
|
23
app/Models/CVInfo.php
Normal file
23
app/Models/CVInfo.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CVInfo extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'cv_infos';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function cv(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CV::class, ownerKey: 'cv_id');
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cv_infos', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('cv_id')->index();
|
||||
$table->string('ip', 255);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cv_infos');
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user