Add database migrations and Eloquent models to support user wallets, transaction history, and discount code functionality. Includes a one-to-one relationship between User and Wallet.
65 lines
1.3 KiB
PHP
65 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use App\Models\Wallet;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, Notifiable;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'phone',
|
|
'role',
|
|
'is_active',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'is_active' => 'boolean',
|
|
'role' => \App\Enums\UserRole::class,
|
|
];
|
|
}
|
|
|
|
public function isSuperAdmin(): bool
|
|
{
|
|
return $this->role === \App\Enums\UserRole::SuperAdmin;
|
|
}
|
|
|
|
public function isTrackingOperator(): bool
|
|
{
|
|
return $this->role === \App\Enums\UserRole::TrackingOperator;
|
|
}
|
|
|
|
public function isDataEntry(): bool
|
|
{
|
|
return $this->role === \App\Enums\UserRole::DataEntry;
|
|
}
|
|
|
|
public function isCustomer(): bool
|
|
{
|
|
return $this->role === \App\Enums\UserRole::Customer;
|
|
}
|
|
|
|
//کیف پول
|
|
public function wallet()
|
|
{
|
|
return $this->hasOne(Wallet::class);
|
|
}
|
|
}
|