'Unarchive', self::FILTER_ARCHIVE => 'Archive', self::FILTER_ACTIVE => 'Active', self::FILTER_INACTIVE => 'Inactive', ]; const PRIVACY_FILTER_ARRAY = [ self::PRIVACY_FILTER_PUBLIC => 'Public', self::PRIVACY_FILTER_PRIVATE => 'Private', ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'first_name', 'last_name', 'email', 'password', 'phone', 'last_seen', 'is_online', 'about', 'photo', 'activation_code', 'is_active', 'is_system', 'email_verified_at', 'player_id', 'is_subscribed', 'gender', 'privacy', 'language', 'is_super_admin', 'role_id', ]; const LANGUAGES = [ 'en' => 'English', 'es' => 'Spanish', 'fr' => 'French', 'de' => 'German', 'ru' => 'Russian', 'pt' => 'Portuguese', 'ar' => 'Arabic', 'zh' => 'Chinese', 'tr' => 'Turkish', 'it' => 'Italian', ]; public static $PATH = 'users'; const HEIGHT = 250; const WIDTH = 250; const MALE = 1; const FEMALE = 2; /** * @var string[] */ protected $with = ['roles']; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; protected $appends = [ 'role_name', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'id' => 'integer', 'name' => 'string', 'email_verified_at' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'is_subscribed' => 'boolean', 'player_id' => 'string', 'privacy' => 'integer', 'gender' => 'integer', 'archive' => 'integer', ]; /** * Validation rules * * @var array */ public static $rules = [ 'name' => 'required|string|max:100', 'phone' => 'nullable|integer', 'role_id' => 'required|integer', 'privacy' => 'required', // 'phone' => 'nullable|regex:/^([0-9\s\-\+\(\)]*)$/', 'email' => 'required|email|max:255|regex:/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', // 'gender' => 'required|integer', ]; public static $messages = [ 'phone.integer' => 'Please enter valid phone number', 'phone.digits' => 'The phone number must be 10 digits long', 'email.regex' => 'Please enter valid email', 'role_id.required' => 'Please select user role', ]; public function getNameAttribute($value) { $user = User::find($this->id); if ($user) { return $user->first_name.' '.$user->last_name; } } /** * @param $value * * @return string */ public function getPhotoAttribute($value) { if (!empty($value)) { return $this->imageUrl(self::$PATH.DIRECTORY_SEPARATOR.$value); } if ($this->gender == self::MALE) { return asset('assets/icons/male.png'); } if ($this->gender == self::FEMALE) { return asset('assets/icons/female.png'); } return getUserImageInitial($this->id, $this->name); } /** * @return string */ public function getRoleNameAttribute() { $userRoles = $this->roles->first(); return (!empty($userRoles)) ? $userRoles->name : ''; } /** * @return string */ /*public function getRoleIdAttribute() { $userRoles = $this->roles->first(); return (!empty($userRoles)) ? $userRoles->id : ''; }*/ /** * @return array */ public function webObj() { return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, 'phone' => $this->phone, 'last_seen' => $this->last_seen, 'about' => $this->about, 'photo' => $this->photo, 'gender' => $this->gender, 'privacy' => $this->privacy, ]; } /** * @return array */ public function apiObj() { return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, 'email_verified_at' => (!empty($this->email_verified_at)) ? $this->email_verified_at->toDateTimeString() : '', 'phone' => $this->phone, 'last_seen' => $this->last_seen, 'is_online' => $this->is_online, 'is_active' => $this->is_active, 'gender' => $this->gender, 'about' => $this->about, 'photo' => $this->photo, 'activation_code' => $this->activation_code, 'created_at' => (!empty($this->created_at)) ? $this->created_at->toDateTimeString() : '', 'updated_at' => (!empty($this->updated_at)) ? $this->updated_at->toDateTimeString() : '', 'is_system' => $this->is_system, 'role_name' => (!$this->roles->isEmpty()) ? $this->roles->first()->name : null, 'role_id' => (!$this->roles->isEmpty()) ? $this->roles->first()->id : null, 'privacy' => $this->privacy, 'archive' => (!empty($this->deleted_at)) ? 1 : 0, ]; } /** * @return bool */ public function deleteImage() { $image = $this->getRawOriginal('photo'); if (empty($image)) { return true; } $this->update(['photo' => null]); return $this->traitDeleteImage(self::$PATH.DIRECTORY_SEPARATOR.$image); } /** * @return HasMany */ public function blockedBy() { return $this->hasMany(BlockedUser::class, 'blocked_by'); } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function devices() { return $this->hasMany(UserDevice::class, 'user_id'); } /** * @return HasOne */ public function userStatus() { return $this->hasOne(UserStatus::class); } /** * @return HasOne */ public function reportedUser() { return $this->hasOne(ReportedUser::class, 'reported_to')->where('reported_by', '=', Auth::id()); } public function role() { return $this->hasOne(Role::class, 'id', 'role_id'); } public function roles() { return $this->hasMany(Role::class, 'id', 'role_id'); } public function hasRole($name) { return $this->role->type == $name || $this->role->name = $name; } }