<?php

namespace App\Models;

use Spatie\Permission\Models\Role;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

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

     public function areas(): BelongsToMany
    {
        return $this->belongsToMany(Role::class);
    }

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

        return $this->areas()
            ->wherePivot('role_id', $request)
            ->exists();
    }
}
