Files
Sistema-Educativo-Laravel/app/Models/Nivel.php
T

29 lines
589 B
PHP

<?php
namespace App\Models;
use App\Models\Plantel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Nivel extends Model
{
protected $guarded = [];
public function nivelPlantel() : BelongsToMany
{
return $this->belongsToMany(Plantel::class)->withPivot('plantel_id');
}
public function existe($plantelId = null)
{
if (!$plantelId) {
return false;
}
return $this->nivelPlantel()
->wherePivot('plantel_id', $plantelId)
->exists();
}
}