<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

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

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

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

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

}
