It's probably because you're not actually doing anything with the return value of the function you've created. The function returns either a
boolean
or the result of a function call to
view('dashboard/index', false);
, but you don't do anything with either result.
Instead you could make the function return
true
or
false
and then do something different in each instance?
if (!function_exists('chkPermissions')) {
function chkPermissions($action) {
$roleid = session()->get('roleid');
$router = service('router');
$controller = class_basename($router->controllerName());
$model = new ModelPermissions();
$data = $model->where([
'roleid' => $roleid,
'controller' => $controller, $action => '1'])->first();
if ($data == null) {
session()->setFlashdata('error', 'Permission not grantted, try again!');
return false;
}
return true;
}
}
public function index()
{
if (!chkPermissions('view'))
return view('dashboard/index', false);
return view('home/index');
}