Files
kulakpos_web/public/restaurant/Modules/Authentication/app/Models/User.php

126 lines
2.8 KiB
PHP
Raw Normal View History

2026-03-15 17:08:23 +07:00
<?php
namespace Modules\Authentication\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Modules\Authentication\Database\Factories\UserFactory;
use Modules\RestaurantDelivery\Models\Rider;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, HasRoles, Notifiable, SoftDeletes;
public const TABLE_NAME = 'users';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'restaurant_id',
'first_name',
'last_name',
'username',
'email',
'phone',
'password',
'otp_code',
'isVerified',
'email_verified_at',
'address',
'avatar',
'role_id',
'user_type',
'facebook',
'twitter',
'linkedin',
'google_plus',
'nid',
'platform',
'device_info',
'last_active_time',
'status',
'bio',
'fcm_token',
'qr_code',
'department_id',
'designation_id',
'salary_type_id',
'address',
'gender',
'date_of_birth',
'joining_date',
'basic_salary',
'created_by',
'deleted_at',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
public function role(): HasOne
{
return $this->hasOne(Role::class, 'id', 'role_id');
}
public function restaurant(): HasOne
{
return $this->hasOne(Restaurant::class, 'id', 'restaurant_id')->select('id', 'name', 'address', 'domain');
}
public function rider(): HasOne
{
return $this->hasOne(Rider::class, 'user_id', 'id');
}
public function customer(): HasOne
{
return $this->hasOne(User::class);
}
protected static function newFactory(): UserFactory
{
return UserFactory::new();
}
// Example: single FCM token
public function routeNotificationForFcm(): mixed
{
return $this->fcm_token;
}
// Or for multiple devices
public function getDeviceTokens(): mixed
{
return $this->deviceTokens()->pluck('token')->toArray();
}
}