first change

This commit is contained in:
2025-07-27 17:40:56 +05:45
commit f8b9a6725b
3152 changed files with 229528 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<?php
namespace Modules\Employee\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Storage;
use Modules\CCMS\Models\Branch;
use Modules\Employee\Database\Factories\EmployeeFactory;
use Modules\User\Models\ActivityLog;
class Employee extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'first_name',
'middle_name',
'last_name',
'dob',
'email',
'contact',
'mobile',
'photo',
'guardian_name',
'guardian_contact',
'temporary_address',
'permanent_address',
'employee_code',
'join_date',
'gender_id',
'designation_id',
'department_id',
'branch_id',
'user_id',
'status',
'remarks',
];
/**
* Get the employee's full name.
*/
protected function casts(): array
{
return [
"dob" => "date",
"join_date" => "date",
];
}
protected function fullName(): Attribute
{
return Attribute::make(
get: fn() => trim(
implode(' ', array_filter([$this->first_name, $this->middle_name, $this->last_name]))
),
);
}
protected function photo(): Attribute
{
return Attribute::make(
get: fn(string $value) => asset($value),
);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function department()
{
return $this->belongsTo(Department::class, 'department_id');
}
public function designation()
{
return $this->belongsTo(Designation::class, 'designation_id');
}
public function branch()
{
return $this->belongsTo(Branch::class, 'branch_id');
}
public function activityLogs()
{
return $this->hasManyThrough(
ActivityLog::class,
User::class,
'id',
'loggable_id'
)
->where('loggable_type', User::class);
}
protected static function newFactory(): EmployeeFactory
{
return EmployeeFactory::new();
}
public static function getFillableFields()
{
return (new static())->getFillable();
}
}