/**
  * @param $name
  * @throws Exception
  */
 public function delete($name)
 {
     try {
         $role = $this->role->where(['name' => ucwords($name)])->firstOrFail();
         $role->delete();
     } catch (ModelNotFoundException $e) {
         throw new Exception('No role found');
     }
 }
 /**
  * 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'));
 }
 /**
  * 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);
 }
 /**
  * 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'));
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     $fieldworkUsers = User::where('email', 'like', '*****@*****.**')->get();
     $adminRole = Role::where('slug', '=', 'admin')->first();
     foreach ($fieldworkUsers as $user) {
         $user->detachRole($adminRole);
         $user->save();
     }
     DB::table('roles')->delete();
     DB::table('role_user')->delete();
 }
 /**
  * Show the application welcome screen to the user.
  *
  * @return Response
  */
 public function index()
 {
     //add roles
     /*
     $adminRole = Role::create([
         'name' => 'Admin',
         'slug' => 'admin',
         'description' => '', // optional
         'level' => 1, // optional, set to 1 by default
     ]);
     
     $preparacijaRole = Role::create([
         'name' => 'Preparacija',
         'slug' => 'preparacija',
         'description' => '', // optional
         'level' => 2, // optional, set to 1 by default
     ]);
     
     $pogonRole = Role::create([
         'name' => 'Pogon',
         'slug' => 'pogon',
         'description' => '', // optional
         'level' => 3, // optional, set to 1 by default
     ]);
     
     $modulRole = Role::create([
         'name' => 'Modul',
         'slug' => 'modul',
         'description' => '', // optional
         'level' => 4, // optional, set to 1 by default
     ]);
     */
     // attach roles
     //find role
     //$role = Role::find(1); // when you know id
     $role = Role::where('level', 1)->first();
     // when you want to find
     //Admin 1
     //Preparacija 2
     //Pogon 3
     //Modul 4
     //find user
     //$id = 1;
     $id = Auth::id();
     $user = User::find($id);
     $user->attachRole($role);
     // you can pass whole object, or just an id
     // deatach roles
     //$user->detachRole($adminRole); // in case you want to detach role
     //$user->detachAllRoles(); // in case you want to detach all roles
     return view('welcome');
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $training = Training::lists('training_name', 'id');
     $trainees = User::lists('id', 'name');
     $role = Role::where('slug', 'LIKE', 'trainee')->first();
     //dd($trainees);
     $newTrainees = array();
     $test = "";
     foreach ($trainees as $traineesName => $traineeId) {
         $listOfTraineesInRoleTable = Role_user::whereuser_id($traineeId)->firstOrFail();
         if ($listOfTraineesInRoleTable->role_id == $role->id) {
             $traineeHas = UserTraining::whereuser_id($traineeId)->first();
             if ($traineeHas == true) {
                 $test++;
             } else {
                 array_push($newTrainees, $traineeId);
             }
         } else {
             continue;
         }
     }
     //print_r($newTrainees);
     return view('user_traininginfo/create', compact('training', 'trainees', 'newTrainees', 'listOfTraineeInRoleTable'));
 }
Exemple #9
0
 /**
  * A dropdown list of roles the company is allowed to use.
  *
  * @return array
  */
 public function roleListSelect($model = 'p')
 {
     $array = [];
     $roles = Role::where('model', $model)->lists('id', 'name')->toArray();
     return $array;
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $usuarios = UsuariosModel::find($id);
     $roles = array("" => '–Perfil–') + Role::where('status', 1)->lists('description', 'id')->toArray();
     return view('usuario.edit', compact('usuarios', 'roles'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $user = User::find($id);
     $roles = Role::where('level', '<=', 20)->lists('name', 'id');
     return view('user_enterprise.edit', compact('user', 'roles'));
 }
Exemple #12
0
 public function update(Request $request, $user_id = 0)
 {
     // dd($user_id);
     $user = User::with('quran_subjects', 'quran_students')->findOrFail($user_id);
     $user->fill($request->except("password"));
     $user->quran_subjects()->sync($request->input('subjects', []));
     $user->quran_students()->sync($request->input('students', []));
     if ($request->input('user_type') == 1) {
         $role = Role::where('name', 'القرآن الكريم 1')->first();
         $role->name = 'القرآن الكريم 1';
         $role->slug = 'alkraan.alkrym';
     } else {
         $role = Role::where('name', 'القرآن الكريم 2')->first();
         $role->name = 'القرآن الكريم 2';
         $role->slug = 'mkym';
     }
     if ($role) {
         $user->detachAllRoles();
         $user->attachRole($role);
     }
     if ($request->has('password')) {
         $user->password = bcrypt($request->input('password'));
     }
     $user->save();
     $this->processPermissions($user);
     $message = 'تم تعديل حساب ' . $user->name . ' بنجاح';
     if (request('submit') == 'save') {
         return redirect()->back()->with('success', $message);
     }
     return redirect()->route('evaluators.quran.index')->with('success', $message);
 }
 public function postSave(Request $request, $id)
 {
     $user = User::findOrFail($id);
     $user->name = $request->input('name');
     $user->surname = $request->input('surname');
     $user->username = $request->input('username');
     $user->email = $request->input('email');
     $user->email2 = $request->input('email2');
     $user->email3 = $request->input('email3');
     $user->group_id = $request->input('group');
     $password = $request->input('password');
     if ($password != '') {
         $user->password = Hash::make($password);
     }
     $role = $request->input('admin');
     if ($user->is('admin')) {
         $current_role = 'admin';
     } else {
         if ($user->is('groupadmin')) {
             $current_role = 'groupadmin';
         } else {
             $current_role = 'none';
         }
     }
     if ($role != $current_role) {
         if ($current_role != 'none') {
             $user->detachRole(Role::where('slug', '=', $current_role)->first());
         }
         if ($role != 'none') {
             $user->attachRole(Role::where('slug', '=', $role)->first());
         }
     }
     $user->save();
     return redirect(url('admin/show/' . $id));
 }
Exemple #14
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $role;
     if (isset($data['architect'])) {
         $role = Role::where('slug', 'architect')->first();
     } else {
         $role = Role::where('slug', 'buyers')->first();
     }
     if (empty($role)) {
         return back()->with("errors", "error fetching role");
     }
     $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
     if (empty($user)) {
         return back()->with("error", "error user empty");
     }
     $user->attachRole($role);
     return $user;
 }