1 | <?php namespace JobApis\JobsToMail\Models; |
||
7 | class Search extends Model |
||
8 | { |
||
9 | use SoftDeletes; |
||
10 | |||
11 | /** |
||
12 | * Indicates that the IDs are not auto-incrementing. |
||
13 | * |
||
14 | * @var bool |
||
15 | */ |
||
16 | public $incrementing = false; |
||
17 | |||
18 | /** |
||
19 | * The attributes that are mass assignable. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $fillable = [ |
||
24 | 'keyword', |
||
25 | 'location', |
||
26 | 'no_recruiters', |
||
27 | 'user_id', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Boot function from laravel. |
||
32 | */ |
||
33 | 6 | protected static function boot() |
|
34 | { |
||
35 | 6 | parent::boot(); |
|
36 | |||
37 | static::creating(function ($model) { |
||
38 | $model->{$model->getKeyName()} = Uuid::uuid4(); |
||
39 | 6 | }); |
|
40 | 6 | } |
|
41 | |||
42 | /** |
||
43 | * Defines the relationship to User model |
||
44 | * |
||
45 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
46 | */ |
||
47 | 1 | public function user() |
|
51 | |||
52 | /** |
||
53 | * Gets the latest Notification only |
||
54 | * |
||
55 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
56 | */ |
||
57 | public function latestNotification() |
||
58 | { |
||
59 | return $this->hasOne(CustomDatabaseNotification::class) |
||
60 | ->orderBy('created_at', 'desc'); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Defines the relationship to Notification model |
||
65 | * |
||
66 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
67 | */ |
||
68 | public function notifications() |
||
69 | { |
||
70 | return $this->hasMany(CustomDatabaseNotification::class); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Limits query to "active" searches |
||
75 | * |
||
76 | * @return \Illuminate\Database\Eloquent\Builder |
||
77 | */ |
||
78 | 1 | public function scopeActive($query) |
|
84 | |||
85 | /** |
||
86 | * Limits query to searches by user with specific email |
||
87 | * |
||
88 | * @return \Illuminate\Database\Eloquent\Builder |
||
89 | */ |
||
90 | public function scopeWhereUserEmail($query, $email = null) |
||
96 | |||
97 | /** |
||
98 | * Limits query to searches by user with specific id |
||
99 | * |
||
100 | * @return \Illuminate\Database\Eloquent\Builder |
||
101 | */ |
||
102 | public function scopeWhereUserId($query, $id = null) |
||
108 | } |
||
109 |