<?php

namespace App\Http\Controllers\Helper;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class GlobalController extends Controller
{
    public static function user_can($role, array $modules) {
        try{
            if(Auth::user()->name == 'administrator' && Auth::id()==1) return true;
            $user_can = DB::table('sys_permissions')
                ->join('sys_role_has_permissions','sys_role_has_permissions.permission_id','sys_permissions.id')
                ->whereIn('sys_permissions.code',$modules)
                ->where('sys_role_has_permissions.role_id', $role)
                ->exists();
            return $user_can;
        }
        catch (\Exception $e){
            Log::error($e);
        }

    }

}
