<?php

namespace App\Models;

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

class School extends Model
{
	use HasFactory;
	protected $guarded = ['id'];
	protected $casts = [
		'created_at' => 'datetime:Y-m-d H:i:s',
		'updated_at' => 'datetime:Y-m-d H:i:s',
	];

	public function scopeActive($query,$permissions)
  {
		// return $query;
		if(Auth::user()->hasRole('superadmin')){
			return $query;
		}
		else
		{
			return $query->whereIn('code',$permissions);
		}
	}

	public function users()
	{
		return $this->belongsToMany(User::class, 'users_schools');
	}
}
