| @@ -7,9 +7,9 @@ | ||
| 7 | 7 | class User extends Model |
| 8 | 8 | { |
| 9 | 9 | protected $table = 'users'; |
| 10 | 10 | |
| 11 | - protected $guarded = ['ID', 'user_pass']; | |
| 11 | + protected $guarded = ['ID', 'user_pass', 'user_activation_key']; | |
| 12 | 12 | |
| 13 | 13 | protected $hidden = ['user_pass', 'user_activation_key']; |
| 14 | 14 | |
| 15 | 15 | protected $appends = ['full_name']; |
| @@ -49,14 +49,24 @@ | ||
| 49 | 49 | public function staff() { |
| 50 | 50 | return $this->hasOne(Staff::class, 'object_id'); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | + public function metas() | |
| 54 | + { | |
| 55 | + return $this->hasMany(Meta::class, 'object_id', 'ID') | |
| 56 | + ->where('object_type', 'user_meta'); | |
| 57 | + } | |
| 58 | + | |
| 53 | 59 | public function getMeta($key, $default = null) |
| 54 | 60 | { |
| 55 | - $meta = Meta::where('object_type', 'user_meta') | |
| 56 | - ->where('object_id', $this->ID) | |
| 57 | - ->where('key', $key) | |
| 58 | - ->first(); | |
| 61 | + if ($this->relationLoaded('metas')) { | |
| 62 | + $meta = $this->metas->firstWhere('key', $key); | |
| 63 | + } else { | |
| 64 | + $meta = Meta::where('object_type', 'user_meta') | |
| 65 | + ->where('object_id', $this->ID) | |
| 66 | + ->where('key', $key) | |
| 67 | + ->first(); | |
| 68 | + } | |
| 59 | 69 | |
| 60 | 70 | if (!$meta) { |
| 61 | 71 | return $default; |
| 62 | 72 | } |