Commit 0f9c3fdd authored by Nicolas Widart's avatar Nicolas Widart

Adding roles selection to the edit user

parent 9f8d19ff
......@@ -15,12 +15,17 @@ class UserController extends AdminBaseController
* @var \Modules\Session\Entities\User
*/
protected $users;
/**
* @var \Cartalyst\Sentinel\Roles\EloquentRole
*/
protected $roles;
public function __construct()
{
parent::__construct();
$this->users = Sentinel::getUserRepository();
$this->roles = Sentinel::getRoleRepository()->createModel();
}
/**
......@@ -86,8 +91,9 @@ class UserController extends AdminBaseController
Flash::error('User not found');
return Redirect::route('dashboard.user.index');
}
$roles = $this->roles->all();
return View::make('user::admin.users.edit', compact('user'));
return View::make('user::admin.users.edit', compact('user', 'roles'));
}
/**
......@@ -100,11 +106,11 @@ class UserController extends AdminBaseController
public function update($id, UpdateUserRequest $request)
{
$user = $this->users->createModel()->find($id);
$this->users->update($user, $request->all());
Flash::success('User updated.');
$user->roles()->sync($request->roles);
Flash::success('User updated.');
return Redirect::route('dashboard.user.index');
}
......
......@@ -43,6 +43,18 @@
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Role(s)</label>
<select multiple="" class="form-control" name="roles[]">
<?php foreach($roles as $role): ?>
<option value="{{ $role->id }}" <?php echo $user->roles()->whereId($role->id)->get()->count() >= 1 ? 'selected' : '' ?>>{{ $role->name }}</option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">Update</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment