/**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     // Validation rules
     $rules = array('label' => 'required|unique:Permissions,label,' . Route::current()->parameter('permission_id') . ',permission_id', 'isActive' => 'required|in:0,1');
     /** $var \Illuminate\Database\Eloquent\Collection $Roles */
     $Roles = Role::active()->get();
     // IF Roles exist, add roles condition
     if ($Roles->count() > 0) {
         // Gets the array of keys
         $keys = $Roles->modelKeys();
         // Add roles to the IN statement
         $rules['roles'] = 'array|in:' . implode(',', $keys);
     }
     return $rules;
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     // Validation rules
     $rules = array('password' => 'required|same:password2|regex:' . config('app.pwRegex'), 'isActive' => 'required|in:0,1', 'email' => 'required|unique:Users,email|email', 'firstName' => 'required', 'lastName' => 'required');
     /** $var \Illuminate\Database\Eloquent\Collection $Roles */
     $Roles = Role::active()->get();
     // IF Roles exist, add roles condition
     if ($Roles->count() > 0) {
         // Gets the array of keys
         $keys = $Roles->modelKeys();
         // Add roles to the IN statement
         $rules['roles'] = 'array|in:' . implode(',', $keys);
     }
     return $rules;
 }
Пример #3
0
 /**
  * Edit an existing user account
  *
  * @param int $user_id The user being edited ID
  *
  * @return View
  */
 public function do_editUser($user_id)
 {
     // Attempt to find the user
     try {
         $user = User::findOrFail($user_id);
         // IF an invalid user ID was passed, throw a 404
     } catch (ModelNotFoundException $ex) {
         $this->_addDashboardMessage('The user you were looking for does not exist.', 'error');
         return redirect()->route('admin.listusers')->with('dashboardMessages', $this->dashboardMessages);
     }
     // Fetchs old form data
     $oldData = Request::old();
     // IF old form data exists
     if (is_array($oldData) && !empty($oldData)) {
         // Set user roles (is case as array for case of null)
         $userRoles = (array) Request::old('roles');
         // Fill model with old form data
         $user->fill($oldData);
         // Old form data does not exist.  Fetch user roles
     } else {
         $userRoles = $user->roles->modelKeys();
     }
     // Share View Variables
     View::share('user', $user);
     View::share('userRoles', $userRoles);
     View::share('Roles', Role::active()->get());
     View::share('_pageName', 'Edit ' . $user->firstName . ' ' . $user->lastName);
     View::share('_title', 'Edit ' . $user->firstName . ' ' . $user->lastName);
     View::share('_pageAction', '/Admin/updateUser/' . $user->user_id);
     // Render the template
     return $this->_renderTemplate('Admin.User');
 }