public function getAll(array $attributes = array()) { if (empty($attributes)) { $roles = $this->role->all(); } else { $roles = $this->role->get($attributes); } return $roles; }
private function save(Role $role, array $inputs) { $role->name = ucfirst($inputs['name']); if (empty($inputs['slug'])) { $role->slug = Str::slug($inputs['name'], '.'); } else { $role->slug = $inputs['slug']; } $role->description = $inputs['description']; $role->level = $inputs['level']; $role->save(); }
public function deleteBulk(Request $req, Role $RoleModel) { // if the table_records is empty we redirect to the roles index if (!$req->has('table_records')) { return redirect()->route('roles.index'); } $ids = array_filter($req->input('table_records'), function ($id) { return $id != 1; }); // we delete all the roles with the ids $ids $RoleModel->destroy($ids); // we redirect to the role index view with a success message return redirect()->route('roles.index')->with('success', trans('users::roles.delete_bulk_success')); }
/** * Run the database seeds. * * @return void */ public function run() { $peliculas = Permission::create(['name' => 'Peliculas', 'slug' => 'Peliculas', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Peliculas']); $realizadores = Permission::create(['name' => 'Realizadores', 'slug' => 'Realizadores', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Realizadores']); $traficos = Permission::create(['name' => 'Traficos', 'slug' => 'Traficos', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Traficos']); // $funcion = Permission::create(['name' => 'Funciones', 'slug' => 'funciones', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Funciones']); $programa = Permission::create(['name' => 'Programas', 'slug' => 'Programas', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Programas']); $festivales = Permission::create(['name' => 'Festivales', 'slug' => 'Festivales', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Festivales']); $sedes = Permission::create(['name' => 'Sedes', 'slug' => 'Sedes', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Sedes']); $integrantes = Permission::create(['name' => 'Integrantes', 'slug' => 'Integrantes', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Integrantes']); $caracteristicas = Permission::create(['name' => 'Caracteristicas', 'slug' => 'Caracteristicas', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Caracteristicas']); $paquetes = Permission::create(['name' => 'Paquetes', 'slug' => 'Paquetes', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Paquetes']); $patrocinadores = Permission::create(['name' => 'Patrocinadores', 'slug' => 'Patrocinadores', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Patrocinadores']); $reportes = Permission::create(['name' => 'Reportes', 'slug' => 'Reportes', 'description' => 'Agregar,Modificar,Consultar,Exportar,Eliminar Reportes']); $roleAdministrador = Role::find(1); $roleEjectivo = Role::find(2); $roleAdministrador->attachPermission($peliculas); $roleAdministrador->attachPermission($realizadores); $roleAdministrador->attachPermission($traficos); $roleAdministrador->attachPermission($funcion); $roleAdministrador->attachPermission($programa); $roleAdministrador->attachPermission($festivales); $roleAdministrador->attachPermission($sedes); $roleAdministrador->attachPermission($integrantes); $roleAdministrador->attachPermission($caracteristicas); $roleAdministrador->attachPermission($paquetes); $roleAdministrador->attachPermission($patrocinadores); $roleAdministrador->attachPermission($reportes); $roleEjectivo->attachPermission($reportes); }
/** * Run the database seeds. * * @return void */ public function run() { $adminRole = Role::create(['name' => 'Admin', 'slug' => 'admin', 'description' => '', 'level' => 1]); $adminRole = Role::create(['name' => 'Secretaria', 'slug' => 'secretaria', 'description' => '', 'level' => 2]); $adminRole = Role::create(['name' => 'Especialista', 'slug' => 'especialista', 'description' => '', 'level' => 3]); $adminRole = Role::create(['name' => 'Usuario', 'slug' => 'usuario', 'description' => '', 'level' => 4]); }
public function unsetAll(Request $request, $role_id) { $role = Role::find($role_id); $role->detachAllPermissions(); $method = new \ReflectionMethod('App\\Http\\Controllers\\AclController', 'index'); return $method->invoke($this); }
public function edit_user($id) { $user = User::findOrFail($id); $role_id = Role_user::whereUser_id($user->id)->first()->role_id; $roles = Role::all(); return view('user.edit_user', compact('roles'), compact('user'))->with('role_id', $role_id); }
public function run() { /* * Create user and role ADMIN */ $user = User::create(['name' => 'admin', 'email' => '*****@*****.**', 'password' => 'admin']); $adminRole = Role::create(['name' => 'Admin', 'slug' => 'admin']); $user->attachRole($adminRole); /* * Create user and role MODERATOR */ $user = User::create(['name' => 'moderator', 'email' => '*****@*****.**', 'password' => 'moderator']); $moderatorRole = Role::create(['name' => 'Moderator', 'slug' => 'moderator']); $user->attachRole($moderatorRole); /* * Create user and role USER */ $user = User::create(['name' => 'user', 'email' => '*****@*****.**', 'password' => 'user']); $userRole = Role::create(['name' => 'User', 'slug' => 'user']); $user->attachRole($userRole); /* * Create user and role badUser - not verified user */ $user = User::create(['name' => 'test', 'email' => '*****@*****.**', 'password' => 'test']); $badUserRole = Role::create(['name' => 'badUser', 'slug' => 'bad.user']); $user->attachRole($badUserRole); }
/** * Update the specified resource in storage. * * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $role = Role::findorFail($id); // Update Permissions $permissions = $request->get('permissions'); $role->detachAllPermissions(); if ($permissions) { foreach ($permissions as $permission) { $role->attachPermission($permission); } } /* PermissionRoleCompany::where('role_id', $id)->delete(); $permissions = $request->get('permissions'); if ($permissions) { $data = []; foreach ($permissions as $permission) { $data[] = [ 'permission_id' => $permission, 'role_id' => $id, 'company_id' => Auth::user()->company->id ]; } PermissionRoleCompany::insert($data); }*/ Toastr::success("Saved changes"); // Get Permissions $rt = getRoleTypes(); $pt = getPermissionTypes(); //$permissions = PermissionRoleCompany::where('role_id', $role->id)->lists('permission_id')->toArray(); $permissions = $role->permissions->lists('id')->toArray(); return view('manage/role/edit', compact('role', 'permissions', 'pt', 'rt')); }
/** * Run the database seeds. * * @return void */ public function run() { $sector = Permission::create(['name' => 'sector', 'slug' => 'sector', 'description' => 'Modulo sector']); $invernadero = Permission::create(['name' => 'invernadero', 'slug' => 'invernadero', 'description' => 'Modulo sector']); $invernaderoPlantula = Permission::create(['name' => 'invernaderoPlantula', 'slug' => 'invernaderoPlantula', 'description' => 'Modulo invernadero']); $reportes = Permission::create(['name' => 'reportes', 'slug' => 'reportes', 'description' => 'Modulo invernaderoPlantula']); $administracion = Permission::create(['name' => 'administracion', 'slug' => 'administracion', 'description' => 'Modulo administracion sin gestion usuarios']); $gestionarUsuarios = Permission::create(['name' => 'gestionarUsuarios', 'slug' => 'gestionarUsuarios', 'description' => 'Gestion usuarios']); $administrador = Role::find(1); $tecnico = Role::find(2); $becario = Role::find(3); $administrador->attachPermission($sector); $administrador->attachPermission($invernadero); $administrador->attachPermission($invernaderoPlantula); $administrador->attachPermission($administracion); $administrador->attachPermission($reportes); $administrador->attachPermission($gestionarUsuarios); $tecnico->attachPermission($sector); $tecnico->attachPermission($invernadero); $tecnico->attachPermission($invernaderoPlantula); $tecnico->attachPermission($administracion); $tecnico->attachPermission($reportes); $becario->attachPermission($sector); $becario->attachPermission($invernadero); $becario->attachPermission($invernaderoPlantula); $becario->attachPermission($administracion); }
/** * Run the database seeds. * * @return void */ public function run() { #Sistema de Roles #Creando Roles $adminRole = Role::create(['name' => 'Administrador', 'slug' => 'admin', 'description' => 'Super Usuario - No tiene limites', 'level' => 1]); $operativeRole = Role::create(['name' => 'Operativo', 'slug' => 'operativo', 'description' => 'Usuario estandar - No puede alterar inventario', 'level' => 2]); $faker = Faker\Factory::create(); DB::table('users')->truncate(); // factory(App\User::class)->create(array( // 'first_name' => 'Johan', // 'last_name' => 'Rueda', // 'full_name' => 'Johan Rueda', // 'email' => '*****@*****.**', // 'password' => Hash::make('123456'), // 'type' => 'administrador' // )); // factory(App\User::class,49)->create(); $id_admin = \DB::table('users')->insertGetId(array('first_name' => 'Johan', 'last_name' => 'Rueda', 'full_name' => 'Johan Rueda', 'email' => '*****@*****.**', 'password' => bcrypt('jrrg*4543'))); $admin_role = User::find($id_admin); $admin_role->attachRole($adminRole); \DB::table('user_profiles')->insert(array('user_id' => $id_admin, 'bio' => "Administrador Root del sistema", 'website' => 'saludver.dev', 'twitter' => 'https://twitter.com/JjdjJohan')); // Usuarios de Prueba: for ($i = 0; $i < 3; $i++) { $first_name = $faker->name; $last_name = $faker->name; $id = \DB::table('users')->insertGetId(array('first_name' => $first_name, 'last_name' => $last_name, 'full_name' => $first_name . ' ' . $last_name, 'email' => $faker->unique()->email, 'password' => bcrypt('123456'))); \DB::table('user_profiles')->insert(array('user_id' => $id, 'bio' => $faker->paragraph(rand(2, 5)), 'website' => '', 'twitter' => '')); $operative_role = User::find($id); $operative_role->attachRole($operativeRole); } }
private function createPermissions() { $config = config('acl'); $this->validateConfig($config['allowedModels']); $this->validateConfig($config['permissions']); // allowedModels comes first // because there should be (# of allowedModels x # of permissions) // ['Model1', 'Model2', ...] foreach ($config['allowedModels'] as $allowedModel) { // Loop through permissions // ['member' => ['create', 'edit', ...]] // Remember one Role can have more than one Permission foreach ($config['permissions'] as $roleSlug => $permissions) { $this->validateConfig($permissions); // Generate a single Permission // Here we create given permissions, // e.g. ['create', 'edit', ...] foreach ($permissions as $permission) { $newPerm = Permission::create(['name' => ucfirst($permission), 'slug' => $permission]); // Attach generated Permission to each Role // If there were n Permissions on a Role, // There should be n entries of Permission on Role/Permission pivot if ($role = Role::whereSlug($roleSlug)->first()) { $role->attachPermission($newPerm); } // Set default allowed Model // for so-called Entity Check $newPerm->model = $allowedModel; $newPerm->save(); } } } }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // $usuario = \Imprenta\User::All(); $user = array("Usuario" => '–Usuario–') + User::lists('name', 'id')->toArray(); $roles = array("Rol" => '–Rol–') + Role::where('status', 1)->lists('name', 'id')->toArray(); return view('roles.asignar_rol', compact('roles', 'user')); }
public function update(Request $request, $id = 0) { if ($id) { try { $user = User::findOrFail($id); } catch (ModelNotFoundException $e) { $request->flash(); return redirect('admin/user', ['act' => $id, 'errors' => $e]); } } else { return redirect('admin/user'); } $data = ['email' => $request->input('email'), 'name' => $request->input('name'), 'slug' => $request->input('slug')]; $validator = Validator::make($data, ['name' => 'required', 'email' => "required|email|unique:users,email,{$id}", 'slug' => 'required|exists:roles,id']); if ($validator->fails()) { $request->flashExcept('password'); return view('admin.user.show', ['act' => $id, 'user' => [], 'errors' => $validator->messages(), 'roles' => Role::all()]); } else { $user->email = $data['email']; $user->name = $data['name']; if ($request->input('password')) { $user->password = bcrypt($request->input('password')); } $user->detachAllRoles(); $user->attachRole($request->input('slug')); $user->save(); return redirect('admin/user'); } }
/** * Run the migrations. * * @return void */ public function up() { // Role::create(['name' => 'Pastor', 'slug' => 'pastor']); Role::create(['name' => 'Zone Leader', 'slug' => 'zone.leader']); Role::create(['name' => 'Volunteer', 'slug' => 'volunteer']); }
/** * Run the database seeds. * * @return void */ public function run() { $adminRole = Role::create(['name' => 'Admin', 'slug' => 'admin', 'description' => '', 'level' => 1]); $userAdmin = User::create(['staff_code' => 'IVC00001', 'full_name' => 'Nguyen Tai Hanh', 'email' => '*****@*****.**', 'password' => Hash::make('12345678'), 'phone_number' => '01676460626', 'user_status' => 'Working']); //attached role $userAdmin->attachRole($adminRole); }
public function run() { $users = User::all(); $roles = Role::all(); foreach ($users as $user) { $user->attachRole($roles[rand(0, count($roles) - 1)]); } }
/** * Run the migrations. * * @return void */ public function up() { $root = Role::create(['name' => 'Root', 'slug' => 'root', 'description' => 'Super user']); $admin = Role::create(['name' => 'Admin', 'slug' => 'admin', 'description' => 'Administrator aplikasi']); $user = Role::create(['name' => 'User', 'slug' => 'user', 'description' => 'User biasa']); $user = \App\User::create(['name' => 'Root', 'email' => '*****@*****.**', 'password' => 'root']); $user->attachRole($root); }
/** * Run the database seeds. * * @return void */ public function run() { //create superuser $user = User::create(['name' => 'lia', 'email' => '*****@*****.**', 'password' => bcrypt('qwerty')]); $new_users = User::find('USR001'); $superUserRole = Role::find('RL003'); $new_users->attachRole($superUserRole); }
public function run() { $secSectorial = Role::create(['name' => 'secSectorial', 'slug' => 'sec_sectorial', 'description' => 'Secretaría Sectorial', 'level' => '1']); $secMunicipal = Role::create(['name' => 'secMunicipal', 'slug' => 'sec_municipal', 'description' => 'Secretaría de Planeación Municipal', 'level' => '2']); $secDepartmental = Role::create(['name' => 'secDepartamenta', 'slug' => 'sec_departamental', 'description' => 'Secretaría de Planeación Departamental', 'level' => '3']); $adminMunicipalRole = Role::create(['name' => 'AdminMunicipal', 'slug' => 'admin_municipal', 'description' => 'Administración - Planeación Municipal', 'level' => '4']); $adminDepartamentalRole = Role::create(['name' => 'Admin', 'slug' => 'admin', 'description' => 'Administración - Planeación Departamental', 'level' => '5']); }
public function run() { TestDummy::times(1)->create('Bican\\Roles\\Models\\Role'); Role::create(['name' => 'Printeron', 'slug' => 'Printeron', 'description' => 'Dostep tylko dla pracownikow Printon', 'level' => '40']); Role::create(['name' => 'Printing House', 'slug' => preg_replace('/[\\s-]+/', '-', 'Printing House'), 'description' => 'Drukarnia', 'level' => '30']); Role::create(['name' => 'Advertising Agency', 'slug' => "Advertising-Agency", 'description' => 'Dostep tylko dla Agencji reklamowych', 'level' => '20']); Role::create(['name' => 'Client', 'slug' => "Client", 'description' => 'Klient', 'level' => '10']); }
/** * Display the view to edit a user * @param User $user we receive an inject model of the user ( see method boot of UsersServiceProvider ) * @return \Illuminate\View\View the user edit view edit.blade.php */ public function edit(User $user) { if ($user->type != 'admin') { return redirect()->route('welcome'); } $roles = Role::lists('name', 'id')->toArray(); return view('users::users.edit', compact('user', 'roles')); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); factory(\App\User::class, 50)->create()->each(function ($user) { $user->attachRole(\Bican\Roles\Models\Role::whereSlug('user')->first()); }); Model::reguard(); }
/** * Stubbing test data. * * @param array $overrides */ protected function createTestStub($overrides = []) { $this->user = empty($overrides) ? factory(User::class)->create() : factory(User::class)->create($overrides); $this->user->attachRole(Role::find(2)); $this->article = factory(Article::class)->create(['title' => 'title', 'author_id' => $this->user->id, 'content' => 'description']); $this->article->comments()->save(factory(Comment::class)->make(['author_id' => $this->user->id])); $this->article->tags()->attach(1); $this->article->attachments()->save(factory(Attachment::class)->make()); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $data2 = ['especialidad' => DB::table('especialidades')->lists('especialidad', 'id')]; $especialidades = Especialidad::lists('especialidad', 'id'); $roles = Role::lists('name', 'id'); $selected = array(); $usuario = User::findOrFail($id); return View('admin.users.edit', $data2, compact('roles', 'especialidades', 'selected'))->with('user', $this->user); }
/** * Run the database seeds. * * @return void */ public function run() { $admin = User::create(['name' => 'hsky', 'email' => '*****@*****.**', 'password' => bcrypt('123456')]); $user = User::create(['name' => 'user', 'email' => '*****@*****.**', 'password' => bcrypt('123456')]); $adminRole = Role::where('slug', '=', 'admin')->first(); $userRole = Role::where('slug', '=', 'user')->first(); $admin->attachRole($adminRole); $user->attachRole($userRole); }
public function run() { $roles = Role::all(); $permissions = Permission::all(); foreach ($roles as $role) { for ($i = 0; $i < count($permissions); $i++) { $role->attachPermission($permissions[$i]); } } }
/** * Reverse the migrations. * * @return void */ public function down() { $admin = Role::where('slug', '=', 'admin')->first(); $contributor = Role::where('slug', '=', 'contributor')->first(); $admin->detachAllPermissions(); $contributor->detachAllPermissions(); DB::table('permissions')->delete(); DB::table('permission_user')->delete(); DB::table('permission_role')->delete(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(Request $request, $id) { //$permisorol = PermisoRoleModel::find($id); $permisorol = PermisoRoleModel::join('permission_user', 'permission_role.id', '=', 'permission_user.id')->find($id); $user = array("Usuario" => '–Usuario–') + User::lists('name', 'id')->toArray(); $permiso = array("Permisos" => '–Permisos–') + Permission::where('status', 1)->lists('name', 'id')->toArray(); $roles = array("Rol" => '–Rol–') + Role::where('status', 1)->lists('name', 'id')->toArray(); // $permisos = array("Permisos" => '–Permisos–') + Permission::where('status', 1)->lists('name', 'id')->toArray(); return view('permisos.asignar.edit', compact('permisorol', 'roles', 'user', 'permiso')); }
/** * Run the database seeds. * * @return void */ public function run() { $roles = []; $roles[] = array('name' => 'Admin', 'slug' => 'admin', 'description' => 'The administrator of the website', 'level' => 1); $roles[] = array('name' => 'User', 'slug' => 'user', 'description' => 'The user who register in the website and he/she is not legal', 'level' => 1); $roles[] = array('name' => 'Legal', 'slug' => 'legal', 'description' => 'The user who register and he/she is legal', 'level' => 1); foreach ($roles as $role) { Role::create($role); } }