<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Loan extends Model
{
    use HasFactory;

    protected $fillable = [
        'employee_id',
        'amount',
        'payback_months',
        'remaining',
        'company_id',
        'created_by',
        'updated_by',
        'created_at'
    ];

    public function employee()
    {
        return $this->belongsTo(Employee::class); // Assuming you have an Employee model
    }

    public function company()
    {
        return $this->belongsTo(Company::class); // Assuming you have a Company model
    }
    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            $model->created_by = auth()->id();
        });

        static::updating(function ($model) {
            $model->updated_by = auth()->id();
        });
    }
}