55 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
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;
/**
* @property int $id
* @property string $token
* @property string $recipient
* @property string $email
* @property string $phoneNumber
* @property array $locations
* @property int $views
*/
class CV extends Model
{
use HasFactory;
protected $table = 'cvs';
protected $guarded = [];
protected $casts = [
'locations' => 'array',
'views' => 'integer',
];
protected function phoneNumber(): Attribute
{
return Attribute::make(
get: fn (mixed $value, array $attributes): ?string => str_replace(' ', '', $attributes['phone_number'] ?? ''),
);
}
protected function formattedPhoneNumber(): Attribute
{
return Attribute::make(
get: fn (mixed $value, array $attributes): ?string => $attributes['phone_number'] ?? '',
);
}
public function info(): HasMany
{
return $this->hasMany(CVInfo::class, 'cv_id');
}
public function getRouteKeyName(): string
{
return 'token';
}
}