/** * Проверка прав пользователя для указаной роли * * @param string $strRole * * @return bool */ public function isCompetent($strRole) { $role = Role::whereRole($strRole)->first(); $roleAdmin = Role::whereRole('admin')->first(); $res = RoleUser::whereUserId($this->id)->whereIn('role_id', array($roleAdmin->id, $role->id))->count(); return $res > 0; }
} }); /* |-------------------------------------------------------------------------- | CSRF Protection Filter |-------------------------------------------------------------------------- | | The CSRF filter is responsible for protecting your application against | cross-site request forgery attacks. If this special token in a user | session does not match the one given in this request, we'll bail. | */ Route::filter('csrf', function () { if (Session::token() != Input::get('_token')) { throw new Illuminate\Session\TokenMismatchException(); } }); Route::filter('roleAdmin', function () { $res = RoleUser::whereRoleId(1)->whereUserId(Auth::user()->id)->count(); if ($res == 0) { return Redirect::to('profile'); } }); Route::filter('testRole', function ($route, $request, $value = '') { if (!Auth::user()->isCompetent($value)) { return Redirect::to('profile'); } }); Route::filter('lang', function () { App::setLocale('ru'); });