<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Guru extends Model
{
    protected $fillable = ['id_guru', 'nama_guru'];

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            $latest = static::orderBy('id', 'desc')->first();
            if (!$latest) {
                $model->id_guru = 'GR01';
            } else {
                $number = intval(substr($latest->id_guru, 2)) + 1;
                $model->id_guru = 'GR' . str_pad($number, 2, '0', STR_PAD_LEFT);
            }
        });
    }
}