1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use Laravel\Passport\HasApiTokens; |
6
|
|
|
use Illuminate\Notifications\Notifiable; |
7
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
8
|
|
|
|
9
|
|
|
class User extends Authenticatable |
10
|
|
|
{ |
11
|
|
|
use HasApiTokens, Notifiable; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The attributes that are mass assignable. |
15
|
|
|
* |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $fillable = [ |
19
|
|
|
'name', 'email', 'password', 'image', 'status', 'token' |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The attributes that should be hidden for arrays. |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $hidden = [ |
28
|
|
|
'password', 'remember_token', 'admin' |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* User has many . |
33
|
|
|
* |
34
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
35
|
|
|
*/ |
36
|
|
|
public function oauthAccessToken() |
37
|
|
|
{ |
38
|
|
|
return $this->hasMany('\App\OauthAccessToken'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* User has many . |
43
|
|
|
* |
44
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
45
|
|
|
*/ |
46
|
|
|
public function categories() |
47
|
|
|
{ |
48
|
|
|
// hasMany(RelatedModel, foreignKeyOnRelatedModel = user_id, localKey = id) |
49
|
|
|
return $this->hasMany(Category::class); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* User has many . |
54
|
|
|
* |
55
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
56
|
|
|
*/ |
57
|
|
|
public function bill_receives() |
58
|
|
|
{ |
59
|
|
|
// hasMany(RelatedModel, foreignKeyOnRelatedModel = user_id, localKey = id) |
60
|
|
|
return $this->hasMany(BillReceive::class); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* User has many . |
65
|
|
|
* |
66
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
67
|
|
|
*/ |
68
|
|
|
public function bill_pays() |
69
|
|
|
{ |
70
|
|
|
// hasMany(RelatedModel, foreignKeyOnRelatedModel = user_id, localKey = id) |
71
|
|
|
return $this->hasMany(BillPay::class); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* User has many . |
76
|
|
|
* |
77
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
78
|
|
|
*/ |
79
|
|
|
public function contents() |
80
|
|
|
{ |
81
|
|
|
// hasMany(RelatedModel, foreignKeyOnRelatedModel = user_id, localKey = id) |
82
|
|
|
return $this->hasMany(Content::class); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* User has many . |
87
|
|
|
* |
88
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
89
|
|
|
*/ |
90
|
|
|
public function comments() |
91
|
|
|
{ |
92
|
|
|
// hasMany(RelatedModel, foreignKeyOnRelatedModel = user_id, localKey = id) |
93
|
|
|
return $this->hasMany(Comment::class); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* User belongsToMany . |
98
|
|
|
* |
99
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\belongsToMany |
100
|
|
|
*/ |
101
|
|
|
public function likes() |
102
|
|
|
{ |
103
|
|
|
return $this->belongsToMany('App\Content', 'likes', 'user_id', 'content_id'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* User belongsToMany . |
108
|
|
|
* |
109
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\belongsToMany |
110
|
|
|
*/ |
111
|
|
|
public function friends() |
112
|
|
|
{ |
113
|
|
|
return $this->belongsToMany('App\User', 'friends', 'user_id', 'friend_id'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function followers() |
117
|
|
|
{ |
118
|
|
|
return $this->belongsToMany('App\User', 'friends', 'friend_id', 'user_id'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getImageAttribute($value) |
122
|
|
|
{ |
123
|
|
|
return asset($value); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function findForPassport($username) |
127
|
|
|
{ |
128
|
|
|
return $this->where('email', $username)->where('status', 1)->first(); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|