1
|
|
|
<?php namespace JobApis\JobsToMail\Models; |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Eloquent\Model; |
4
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
5
|
|
|
use Ramsey\Uuid\Uuid; |
6
|
|
|
|
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
|
|
|
'user_id', |
25
|
|
|
'keyword', |
26
|
|
|
'location', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Boot function from laravel. |
31
|
|
|
*/ |
32
|
6 |
|
protected static function boot() |
33
|
|
|
{ |
34
|
6 |
|
parent::boot(); |
35
|
|
|
|
36
|
|
|
static::creating(function ($model) { |
37
|
1 |
|
$model->{$model->getKeyName()} = Uuid::uuid4(); |
38
|
6 |
|
}); |
39
|
6 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Defines the relationship to User model |
43
|
|
|
* |
44
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
45
|
|
|
*/ |
46
|
4 |
|
public function user() |
47
|
|
|
{ |
48
|
4 |
|
return $this->belongsTo(User::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Limits query to "active" searches |
53
|
|
|
* |
54
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
55
|
|
|
*/ |
56
|
1 |
|
public function scopeActive($query) |
57
|
|
|
{ |
58
|
|
|
return $query->whereHas('user', function ($query) { |
59
|
1 |
|
return $query->confirmed(); |
60
|
1 |
|
}); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Limits query to searches by user with specific email |
65
|
|
|
* |
66
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
67
|
|
|
*/ |
68
|
1 |
|
public function scopeWhereUserEmail($query, $email = null) |
69
|
|
|
{ |
70
|
|
|
return $query->whereHas('user', function ($query) use ($email) { |
71
|
1 |
|
return $query->where('email', $email); |
72
|
1 |
|
}); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Limits query to searches by user with specific id |
77
|
|
|
* |
78
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
79
|
|
|
*/ |
80
|
|
|
public function scopeWhereUserId($query, $id = null) |
81
|
|
|
{ |
82
|
1 |
|
return $query->whereHas('user', function ($query) use ($id) { |
83
|
1 |
|
return $query->where('id', $id); |
84
|
1 |
|
}); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|