*/ protected $fillable = [ 'name', 'phone', 'email', 'status', 'password', 'gender_id', 'role_id', 'outlet_id', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; protected function genderId(): Attribute { return Attribute::make( get:fn($value) => $value == 1 ? __('words.female') : __('words.male'), ); } protected function status(): Attribute { return Attribute::make( get:fn($value) => $value ? __('words.active') : __('words.not_active'), ); } public function role() { return $this->belongsTo(Role::class); } public function outlet() { return $this->belongsTo(Outlet::class); } public function expenses() { return $this->hasMany(Expense::class); } public function transactions() { return $this->hasMany(Transaction::class); } public function scopeFilter($query, array $filters) { $query->when($filters['search'] ?? null, function ($query, $search) { $query->where(function ($query) use ($search) { $query->where('name', 'like', '%' . $search . '%') ->orWhere('phone', 'like', '%' . $search . '%') ->orWhere('email', 'like', '%' . $search . '%'); }); }); } public function hasRole($role) { return $this->role()->where('name', $role)->first() ? true : false; } }