1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
7
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
8
|
|
|
use Illuminate\Notifications\Notifiable; |
9
|
|
|
use jeremykenedy\LaravelRoles\Traits\HasRoleAndPermission; |
10
|
|
|
|
11
|
|
|
class User extends Authenticatable |
12
|
|
|
{ |
13
|
|
|
use HasRoleAndPermission; |
|
|
|
|
14
|
|
|
use Notifiable; |
|
|
|
|
15
|
|
|
use SoftDeletes; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The database table used by the model. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $table = 'users'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The attributes that are not mass assignable. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $guarded = ['id']; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The attributes that are mass assignable. |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $fillable = [ |
37
|
|
|
'name', |
38
|
|
|
'first_name', |
39
|
|
|
'last_name', |
40
|
|
|
'email', |
41
|
|
|
'password', |
42
|
|
|
'activated', |
43
|
|
|
'token', |
44
|
|
|
'signup_ip_address', |
45
|
|
|
'signup_confirmation_ip_address', |
46
|
|
|
'signup_sm_ip_address', |
47
|
|
|
'admin_ip_address', |
48
|
|
|
'updated_ip_address', |
49
|
|
|
'deleted_ip_address', |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The attributes that should be hidden for arrays. |
54
|
|
|
* |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $hidden = [ |
58
|
|
|
'password', |
59
|
|
|
'remember_token', |
60
|
|
|
'activated', |
61
|
|
|
'token', |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
protected $dates = [ |
65
|
|
|
'deleted_at', |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Build Social Relationships. |
70
|
|
|
* |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
public function social() |
74
|
|
|
{ |
75
|
|
|
return $this->hasMany('App\Models\Social'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* User Profile Relationships. |
80
|
|
|
* |
81
|
|
|
* @var array |
82
|
|
|
*/ |
83
|
|
|
public function profile() |
84
|
|
|
{ |
85
|
|
|
return $this->hasOne('App\Models\Profile'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// User Profile Setup - SHould move these to a trait or interface... |
89
|
|
|
|
90
|
|
|
public function profiles() |
91
|
|
|
{ |
92
|
|
|
return $this->belongsToMany('App\Models\Profile')->withTimestamps(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function hasProfile($name) |
96
|
|
|
{ |
97
|
|
|
foreach ($this->profiles as $profile) { |
98
|
|
|
if ($profile->name == $name) { |
99
|
|
|
return true; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function assignProfile($profile) |
107
|
|
|
{ |
108
|
|
|
return $this->profiles()->attach($profile); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function removeProfile($profile) |
112
|
|
|
{ |
113
|
|
|
return $this->profiles()->detach($profile); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|