public function test(Request $request) { // $user = User::find(1); // // if($user->hasRole('Founder')){ // return '您是创始人'.'ID:'.$user->id; // }; if ($request->user()) { // $userRoles = $request->user()->roles()->get(); // foreach($userRoles as $r){ // $roles[] = $r->name; // } // var_dump($roles); $userRoles = Role::all(); foreach ($userRoles as $r) { $roles[] = $r->name; } if (!$request->user()->hasRole($roles)) { return redirect()->guest('auth/login'); } //$can = Route::currentRouteName();//当前route-name exp:user.test $can = Route::currentRouteAction(); echo $can; $res = $request->user()->can($can); echo $res; } }
public function LngCompose($view) { $arrLng = Languages::all()->toArray(); $action = Route::currentRouteAction(); $params = Route::getCurrentRoute()->parameters(); $arrAction = explode("\\", $action); $controller = array_pop($arrAction); $view->with(compact('arrLng', 'action', 'controller', 'params')); }
public function lian() { echo "MoooController/lian"; echo "<hr>"; $url = route('lian'); var_dump($url); $action = Route::currentRouteAction(); var_dump($action); }
/** * Initialize Laravel-MultiAlerts. * * @param array $routes * @param string $namespace * @return $this */ public function initialize($routes, $namespace = '') { $this->routes = $routes; $configKey = sprintf('gsmeira.routetracker.namespaces.%s', $namespace); $this->namespace = config($configKey, 'App\\Http\\Controllers'); $this->currentAction = trim(str_replace($this->namespace, '', Route::currentRouteAction()), '\\'); if (strpos($this->currentAction, '@') !== false) { list($this->currentController, $this->currentMethod) = explode('@', $this->currentAction); } $this->isCurrent = $this->hasCurrent($routes); return $this; }
public function check($controller_suffix = 'Controller') { $routeAction = Route::currentRouteAction(); preg_match_all('/([a-z0-9A-Z]+\\\\)?(\\w+)@(\\w+)/', $routeAction, $matchs); $controller_full = $matchs[2][0]; //类名 $controller = str_replace($controller_suffix, '', $controller_full); $action = $matchs[3][0]; //方法名 //不需要认证的模块,则放行 if (isset($this->config['AUTH_LOGIN_NO'][$controller]) && ($this->config['AUTH_LOGIN_NO'][$controller] == '*' || in_array($action, $this->config['AUTH_LOGIN_NO'][$controller]))) { return true; } //没有登陆跳转到登陆页面 if (!$this->checkLogin()) { //todo return $this->noLogin(); } $power = $this->getRolePower(Session::get($this->config['AUTH_SESSION_PREFIX'] . 'role_id')); //临时的,记得删除-1 todo //$power = -1; if ($power == -1) { return true; } else { $privilege = Lang::has('privilege') ? Lang::get('privilege') : array(); $controller = str_replace('Controller', '', $controller); if ($privilege) { if (isset($privilege[$controller]['power_rule']['module_hidden'])) { if ($privilege[$controller]['power_rule']['module_hidden'] == 0) { if (isset($privilege[$controller][$action])) { if (isset($privilege[$controller]['power_rule'][$action]) && $privilege[$controller]['power_rule'][$action] == 1) { return true; } else { if (isset($power[$controller][$action]) && $power[$controller][$action] == -1) { return true; } } } else { //没有设置$privilege[$controller][$action]一律通过 return true; } } elseif ($privilege[$controller]['power_rule']['module_hidden'] == 1) { return true; } } } } return $this->noPower(); }
public function __construct() { LogR::register(last(explode('\\', get_class($this))) . ' ' . explode('@', Route::currentRouteAction())[1]); }
echo $ulLiSubElement; } ?> ><a href="{{route('admin::user.create')}}">Gebruiker toevoegen</a></li> </ul> </li> <li class="list-divider"></li> <?php $liMainElement = ""; $ulSubElement = "class=\"collapse\""; $ulLiSubElement = ""; $currentRouteName = Route::currentRouteName(); $currentRouteAction = Route::currentRouteAction(); if (starts_with($currentRouteAction, "WI\\Core\\Entities")) { $liMainElement = "class=\"active-x active-sub\""; $ulSubElement = "class=\"collapse in\""; $ulLiSubElement = "class=\"active-link\""; } ?> <!--User list item--> <li <?php echo $liMainElement; ?> > <a href="#"> <i class="psi-gear-2"></i> <span class="menu-title"> <strong>Systeem</strong>
/** * Returns the current controller actions method name. * * @param string $method * * @return string */ function currentControllerAction($method) { $class = explode('@', Route::currentRouteAction()); return sprintf('%s@%s', $class[0], $method); }