|
1
|
|
|
<?php namespace JobApis\JobsToMail\Models; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
4
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
5
|
|
|
use Illuminate\Notifications\Notifiable; |
|
6
|
|
|
use Ramsey\Uuid\Uuid; |
|
7
|
|
|
|
|
8
|
|
|
class User extends Model |
|
9
|
|
|
{ |
|
10
|
|
|
use Notifiable, SoftDeletes; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Indicates that the IDs are not auto-incrementing. |
|
14
|
|
|
* |
|
15
|
|
|
* @var bool |
|
16
|
|
|
*/ |
|
17
|
|
|
public $incrementing = false; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The attributes that are mass assignable. |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $fillable = [ |
|
25
|
|
|
'email', |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Boot function from laravel. |
|
30
|
|
|
*/ |
|
31
|
15 |
|
protected static function boot() |
|
32
|
|
|
{ |
|
33
|
15 |
|
parent::boot(); |
|
34
|
|
|
|
|
35
|
15 |
|
static::creating(function ($model) { |
|
36
|
2 |
|
$model->{$model->getKeyName()} = Uuid::uuid4(); |
|
37
|
15 |
|
}); |
|
38
|
15 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Gets the user's maximum number of allowed searches |
|
42
|
|
|
* |
|
43
|
|
|
* @return int |
|
44
|
|
|
*/ |
|
45
|
2 |
|
public function getMaxSearchesAttribute($value): int |
|
46
|
|
|
{ |
|
47
|
2 |
|
return $value ?? (int) config('app.max_searches'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Defines the relationship to Search model |
|
52
|
|
|
* |
|
53
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function searches() |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->hasMany(Search::class); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Defines the relationship to Token model |
|
62
|
|
|
* |
|
63
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
64
|
|
|
*/ |
|
65
|
2 |
|
public function tokens() |
|
66
|
|
|
{ |
|
67
|
2 |
|
return $this->hasMany(Token::class); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Limits query to "confirmed" users |
|
72
|
|
|
* |
|
73
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
|
74
|
|
|
*/ |
|
75
|
2 |
|
public function scopeConfirmed($query) |
|
76
|
|
|
{ |
|
77
|
2 |
|
return $query->whereNotNull('confirmed_at'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Limits query to "unconfirmed" users |
|
82
|
|
|
* |
|
83
|
|
|
* @param $query \Illuminate\Database\Eloquent\Builder |
|
84
|
|
|
* |
|
85
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function scopeUnconfirmed($query) |
|
88
|
|
|
{ |
|
89
|
1 |
|
return $query->whereNull('confirmed_at'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Defines the relationship to Notification model |
|
94
|
|
|
* |
|
95
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
96
|
|
|
*/ |
|
97
|
|
|
public function notifications() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->morphMany(CustomDatabaseNotification::class, 'notifiable') |
|
100
|
|
|
->orderBy('created_at', 'desc'); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|