<?php

namespace App\Models;

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

class Loan extends Model
{
    use HasFactory;
    protected $guarded = [];
    public function user(){
        return $this->belongsTo(User::class);
    }

    public static function idExists($id){
        return Loan::where('loan_id',$id)->exists();
    }

    public static function generateLoanID(){
        $id = mt_rand(1000,9999);
        if(Self::idExists($id)){
            return Self::generateLoanID();
        }
        return $id;
    }
}
