File size: 2,104 Bytes
40dca3b
 
 
 
 
0c117c4
40dca3b
 
 
 
0c117c4
 
 
 
40dca3b
0c117c4
 
 
40dca3b
0c117c4
40dca3b
 
 
 
 
 
 
 
 
 
0c117c4
 
 
 
 
 
40dca3b
 
0c117c4
 
40dca3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c117c4
40dca3b
0c117c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40dca3b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Builder;
use Spatie\Permission\Traits\HasRoles;



class User extends Authenticatable implements JWTSubject,MustVerifyEmail
{
    use HasApiTokens, HasFactory, Notifiable,HasRoles;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'first_name',
        "last_name",
        "phone",
		"national",
		"isActive",
		"birthday",
    ];

    protected $table = "users";

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
		'phone_verified_at' => 'datetime',
    ];

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    function bookings(){
        return $this->hasMany(Booking::class,'customer_id');
    }

    public function roomTypes()
    {
        return $this->belongsToMany(RoomType::class, 'wishlists', 'customer_id', 'room_type_id')->withTimestamps();
    }

    function wishlists(){
        return $this->hasMany(WishList::class,'customer_id')->orderBy('updated_at', 'desc');
    }

    public function scopeActive(Builder $query): void
    {
        $query->where('isActive', 1);
    }

    public function scopeVerified(Builder $query): void
    {
        $query->whereNotNull('email_verified_at');
    }
}