<?php

namespace App\Models;

use App\Models\Plantel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Turno extends Model
{
    protected $guarded = [];

    public $timestamps = false;

    public function turnoPlantel() : BelongsToMany
    {
        return $this->belongsToMany(Plantel::class)->withPivot('plantel_id');
    }

    public function existe($plantelId = null)
    {
        if (!$plantelId) {
            return false;
        }

        return $this->turnoPlantel()
            ->wherePivot('plantel_id', $plantelId)
            ->exists();
    }
}
