/**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function edit($id)
 {
     if (!\Entrust::hasRole('admin')) {
         $id = auth()->user()->id;
     }
     $user = User::findOrFail($id);
     $roles = $this->roles;
     return view('user.edit', compact('user', 'roles'));
 }
Example #2
0
 /**
  * Attach role as admin for default provided user
  */
 protected function attachRoleForAdmin()
 {
     $this->line('');
     $this->info(sprintf('Attach role for default admin'));
     $adminEmail = $this->ask("Enter default admin email");
     $user = User::where('email', '=', $adminEmail)->first();
     $role = Role::where('name', '=', 'admin')->first();
     if ($user) {
         if ($user->hasRole('admin')) {
             $this->error(sprintf('%s has been already been assigned with admin role', $adminEmail));
         } else {
             $user->attachRole($role);
             $this->info(sprintf('%s has been assigned with admin role', $adminEmail));
         }
     } else {
         $adminName = $this->ask("Enter default admin name");
         $adminPassword = $this->ask("password");
         $user = User::create(['name' => $adminName, 'email' => $adminEmail, 'phone_number' => '', 'address' => '', 'password' => bcrypt($adminPassword), 'is_active' => '1']);
         $user->attachRole($role);
         $this->info(sprintf('Admin User created with email : %s', $adminEmail));
     }
 }
 /**
  * @param $id
  * @return int
  */
 public function destroy($id)
 {
     return $this->user->destroy($id);
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }