69 lines
1.8 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|null $phoneNumber
* @property array $locations
* @property string|null $mission
* @property string|null $rodo
* @property string|null $position
* @property string|null $notes
* @property int $views
* @property bool $sended
*/
class CV extends Model
{
use HasFactory;
protected $table = 'cvs';
protected $guarded = [];
protected $casts = [
'locations' => 'array',
'views' => 'integer',
'sended' => 'boolean',
'sended_timestamp' => 'datetime',
];
protected function phoneNumber(): Attribute
{
return Attribute::make(
get: fn (mixed $value): string => str_replace(' ', '', $value ?? ''),
set: fn (mixed $value): string => str_replace(' ', '', $value ?? ''),
);
}
protected function formattedPhoneNumber(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes): ?string {
$number = str_replace(' ', '', $attributes['phone_number'] ?? '');
for ($i = 3; $i < 12; $i+=4) {
$number = substr_replace($number, ' ', $i, 0);
}
return $number;
},
);
}
public function info(): HasMany
{
return $this->hasMany(CVInfo::class, 'cv_id');
}
public function getRouteKeyName(): string
{
return 'token';
}
}