*/ protected $fillable = [ 'first_name', 'last_name', 'email', 'phone', 'job_title', 'hire_date', 'active', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'active' => 'boolean', 'hire_date' => 'date', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Get the thanatopractitioner associated with the employee. */ public function thanatopractitioner(): HasOne { return $this->hasOne(Thanatopractitioner::class); } /** * Get the full name of the employee. */ public function getFullNameAttribute(): string { return $this->first_name . ' ' . $this->last_name; } /** * Scope a query to only include active employees. */ public function scopeActive($query) { return $query->where('active', true); } /** * Scope a query to only include inactive employees. */ public function scopeInactive($query) { return $query->where('active', false); } /** * Scope a query to search employees. */ public function scopeSearch($query, string $term) { return $query->where(function ($q) use ($term) { $q->where('first_name', 'like', '%' . $term . '%') ->orWhere('last_name', 'like', '%' . $term . '%') ->orWhere('email', 'like', '%' . $term . '%') ->orWhere('job_title', 'like', '%' . $term . '%'); }); } }