Files
tbbank-new/app/Modules/UserAdjustments/Traits/UserAdjustments.php
2025-11-04 21:07:23 +05:00

87 lines
2.1 KiB
PHP

<?php
namespace App\Modules\UserAdjustments\Traits;
use App\Modules\Branch\Models\Branch;
use App\Modules\Branch\Models\UserBranch;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\Permission\Traits\HasRoles;
/**
* @property string $username [unique]
* @property string|null $first_name
* @property string|null $last_name
* @property string|null $phone
* @property \Illuminate\Support\Facades\Date|null $phone_verified_at
* @property string $locale [default: tk]
* @property bool $password_must_be_changed [default: false]
* @property bool $must_fill_profile [default: false]
* @property null|array<string, int|string|null> $options
*/
trait UserAdjustments
{
use HasRoles;
use RoleCheckers;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'phone_verified_at' => 'datetime',
'password_must_be_changed' => 'bool',
'must_fill_profile' => 'bool',
'options' => 'array',
'custom_fields' => 'array',
'password' => 'hashed',
];
}
/**
* Get option from options
*/
public function getOption(string $option): null|int|string
{
return $this->options && array_key_exists($option, $this->options) ? $this->options[$option] : '';
}
/**
* Passport serie
*/
public function passport_serie(): string
{
return (string) $this->getOption('passport_serie');
}
/**
* Passport id
*/
public function passport_id(): string
{
return (string) $this->getOption('passport_id');
}
/**
* Branches associated with user
*/
public function branches(): BelongsToMany
{
return $this->belongsToMany(Branch::class);
}
/**
* User branches
*
* @return HasMany<UserBranch, $this>
*/
public function userBranches(): HasMany
{
return $this->hasMany(UserBranch::class);
}
}