69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
#[Fillable(['name', 'email', 'password', 'role', 'status', 'subscription_status', 'subscription_expires_at', 'api_token'])]
|
|
#[Hidden(['password', 'remember_token', 'api_token'])]
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, Notifiable;
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'subscription_expires_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function isAdmin(): bool
|
|
{
|
|
return $this->role === 'admin';
|
|
}
|
|
|
|
public function isEmployer(): bool
|
|
{
|
|
return $this->role === 'employer';
|
|
}
|
|
|
|
public function hasActiveSubscription(): bool
|
|
{
|
|
return $this->subscription_status === 'active' && ($this->subscription_expires_at === null || $this->subscription_expires_at > now());
|
|
}
|
|
|
|
public function subscription()
|
|
{
|
|
return $this->hasOne(Subscription::class);
|
|
}
|
|
|
|
public function emiratesIdVerification()
|
|
{
|
|
return $this->hasOne(EmployerProfile::class, 'user_id');
|
|
}
|
|
|
|
public function employerProfile()
|
|
{
|
|
return $this->hasOne(EmployerProfile::class, 'user_id');
|
|
}
|
|
|
|
public function announcements()
|
|
{
|
|
return $this->hasMany(Announcement::class, 'employer_id');
|
|
}
|
|
}
|