public function edit($form, $row) { if (!($data = $this->check(__FUNCTION__, $form))) { return $data; } if ($data['password'] !== $data['password_repeat']) { throw new Exception(__('Passwords must be equals.')); } $exists = Models\User::where('user', '=', $data['user'])->where('id', '!=', $data['id'])->first(); if ($exists) { throw new Exception(__('Already exists another user with user "%s"', $data['user'])); } if ($data['password']) { $data['password'] = Hash::make($data['password']); } elseif (empty($data['id'])) { throw new Exception(__('Password is required for new users')); } else { unset($data['password']); } unset($data['password_repeat']); try { $row = Models\User::replace($data, $row); } catch (Exception $e) { throw new Exception(__('Error storing data: %s', $e->getMessage())); } Session::flash('flash-message', ['message' => __('Data was saved successfully'), 'status' => 'success']); return Redirect::route('admin.management.users.edit', $row->id); }
private function getRow($id) { if (empty($id)) { return new Models\User(); } return Models\User::where('id', $id)->firstOrFail(); }
/** * Execute the console command. * * @return mixed */ public function handle() { $data = $this->option(); $exists = Models\User::where('user', '=', $data['user'])->first(); if ($exists) { $this->error(__('User %s alread exists', $data['user'])); return false; } try { Models\User::create(['name' => $data['name'], 'user' => $data['user'], 'password' => Hash::make($data['password']), 'admin' => $data['admin'] && $data['admin'] !== 'false', 'enabled' => 1]); } catch (Exception $e) { $this->error($e->getMessage()); return false; } $this->info('User created successfully'); }