<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Support\Facades\DB;

class Permission extends Model
{


    public static function can($roleId, $permission, $vue)
    {
        $can = false;
        $vueId =  DB::table('vue')->where('lib', $vue)->first()->id;
        $permissionId = DB::table('type_permission')->where('lib', $permission)->first()->id;

        $permissionRole = DB::table('ligne_permission')->where([
            ['typepermission_id', '=', $permissionId],
            ['role_id', '=', $roleId],
            ['vue_id', '=', $vueId],
        ])->first();
            
        if($permissionRole){
            $can = true;
        }

        return $can;

    }



}
