'datetime', ]; public function teams() { return $this->hasManyThrough('App\Models\Core\Auth\Team', 'App\Models\Core\Auth\TeamUser', 'user_id', 'id', 'id', 'team_id'); } public function scopeByTeam($query, $id) { return $query->whereHas( 'teams', function ($query) use ($id) { $query->where('id', $id); } ); } public function scopeByUniqueTeam($query) { return $query->has('teams', '=', 1); } public function scopeActive($query) { return $query->where('active', 1); } /** * Send the password reset notification. * * @param string $token * @return void */ public function sendPasswordResetNotification($token) { $this->notify(new ResetPasswordNotification($token)); } /** * Send notification when a new user is created. * * @param string $token */ public function sendNewUserNotification($token) { $this->notify(new NewUserNotification($token, $this)); } /** * Return last name in uppercase by default. * * * @return string */ public function getLastNameAttribute($value) { return mb_strtoupper($value); } /** * Return first name with first char of every word in uppercase. * * * @return string */ public function getFirstNameAttribute($value) { return mb_convert_case($value, MB_CASE_TITLE); } /** * Return a concatenation of first name and last_name if field name does not exists. * * * @return string */ public function getNameAttribute($value) { if (! empty($value)) { return $value; } return $this->first_name.' '.$this->last_name; } /** * Return last login date formatted. * * @param string $format * @param string $default * @return mixed|string */ public function getLastLogin($format = 'YYYY-MM-DD HH:mm:ss', $default = '') { if ($this->last_login === null) { return $default; } return Carbon::createFromTimeString($this->last_login)->isoFormat($format); } /** * Return role list as a string. * * @return string */ public function getRolesList() { $res = []; foreach ($this->roles as $role) { $res[] = __($role->display_name); } if (empty($res)) { return '-'; } return implode(', ', $res); } /** * Check if current user has an avatar. * * @return string|false */ public function getAvatarPathAttribute() { return public_path('images/avatars/'.md5($this->id.$this->email).'.jpg'); } /** * Return current user avatar uri. * * @return string */ public function getAvatarUrlAttribute() { if (is_file($this->avatar_path)) { $ts = filemtime($this->avatar_path); return asset('images/avatars/'.md5($this->id.$this->email).'.jpg?t='.$ts); } return asset('/assets/vendor/boilerplate/images/default-user.png'); } }