Esempio n. 1
0
 public function run()
 {
     DB::table('auth_role')->delete();
     $auth_id1 = AuthUser::find(1)->id;
     $auth_id2 = AuthUser::find(2)->id;
     $auth_id3 = AuthUser::find(3)->id;
     $auth_id4 = AuthUser::find(4)->id;
     $auth_id5 = AuthUser::find(5)->id;
     $auth_id6 = AuthUser::find(6)->id;
     $role_id1 = Role::where('name', '=', 'admin')->first()->id;
     $role_id2 = Role::where('name', '=', 'moderator')->first()->id;
     DB::table('auth_role')->insert(array(array('auth_id' => $auth_id1, 'role_id' => $role_id1), array('auth_id' => $auth_id2, 'role_id' => $role_id1), array('auth_id' => $auth_id3, 'role_id' => $role_id2), array('auth_id' => $auth_id4, 'role_id' => $role_id1), array('auth_id' => $auth_id5, 'role_id' => $role_id1), array('auth_id' => $auth_id6, 'role_id' => $role_id1)));
 }
Esempio n. 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function updateRole($id)
 {
     //Making adaptive rules for site_name
     $role_rules = array();
     $roles = array();
     foreach (Input::all() as $k => $v) {
         if (strpos($k, 'role_') !== false) {
             $role_rules[$k] = Config::get('validator.admin.auth_role.role');
             $roles[] = mb_substr($k, strlen('role_'), strlen($k) - strpos($k, 'role_'));
         }
     }
     // Validate the inputs
     $validator = Validator::make(Input::all(), $role_rules);
     // process the login
     if ($validator->passes()) {
         $user = AuthUser::find($id);
         //sync roles
         $user->roles()->sync($roles);
         if ($user->save()) {
             // Redirect to the new blog post user
             return Redirect::to('admin/auth')->with('success', Lang::get('admin.auth_edit_success'));
         }
         // Redirect to the blog post edit user
         return Redirect::to('admin/role/' . $id . '/edit')->with('error', Lang::get('admin.auth_edit_fail'));
     }
     // Form validation failed
     return Redirect::to('admin/role/' . $id . '/edit')->withInput()->withErrors($validator);
 }