<?php

namespace App\Models\Traits;

use App\Models\Scopes\ScoalaScope;
use App\Models\Scoala;

trait BelongsToScoala
{
    public static function bootBelongsToScoala(): void
    {
        static::addGlobalScope(new ScoalaScope());

        static::creating(function ($model) {
            if (!$model->scoala_id && auth()->check() && auth()->user()->scoala_id) {
                $model->scoala_id = auth()->user()->scoala_id;
            }
        });
    }

    public function scoala()
    {
        return $this->belongsTo(Scoala::class);
    }
}
