File "LeaveMaster.php"

Full Path: /home/trinadezambia/public_html/admin_panel/app/Models/LeaveMaster.php
File size: 1.48 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use App\Traits\DateFormatTrait;

class LeaveMaster extends Model
{
    use HasFactory, DateFormatTrait;
    protected $fillable = ['leaves','holiday','session_year_id','school_id'];
    protected $hidden = ['created_at','updated_at'];
    
    public function scopeOwner()
    {
        if (Auth::user()) {
            return $this->where('school_id', Auth::user()->school_id);
        }
    }

    /**
     * Get the session_year that owns the LeaveMaster
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function session_year()
    {
        return $this->belongsTo(SessionYear::class);
    }

    /**
     * Get the school that owns the LeaveMaster
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function school()
    {
        return $this->belongsTo(School::class);
    }

    /**
     * Get all of the leave for the LeaveMaster
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function leave()
    {
        return $this->hasMany(Leave::class);
    }

    public function getCreatedAtAttribute()
    {
        return $this->formatDateValue($this->getRawOriginal('created_at'));
    }

    public function getUpdatedAtAttribute()
    {
        return $this->formatDateValue($this->getRawOriginal('updated_at'));
    }
}