﻿<?php

namespace App\Models;

use Illuminate\Support\Facades\Auth;
use App\Scopes\OrganisationScope;

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

class Performance_Type extends Model
{
    // use HasFactory;

    protected $fillable = [
        'name',
        // 'type',
        'created_by',
        'organisation_id',
    ];

    public function types()
    {
        return $this->hasMany('App\Models\Competencies', 'type', 'id');
    }

    protected static function booted()
    {
        static::addGlobalScope(new OrganisationScope);

        static::creating(function ($model) {
            if (Auth::check()) {
                $model->organisation_id = Auth::user()->organisation_id;
            }
        });
    }