/** * Process datatables ajax request. * * @return \Illuminate\Http\JsonResponse */ public function search() { $auth_account = $this->auth_user->account; //return all accounts when we are in the system account //in a normal account only show the current linked one if ($auth_account->isSystemAccount()) { $accounts = Account::all(); } else { // retrieve the account as a collection $accounts = Account::where('id', '=', $auth_account->id)->get(); } return Datatables::of($accounts)->addColumn('actions', function ($account) { $actions = \Form::open(['route' => ['admin.accounts.destroy', $account->id], 'method' => 'DELETE', 'class' => 'form-inline']); $actions .= ' <a href="accounts/' . $account->id . '" class="btn btn-xs btn-primary"><span class="glyphicon glyphicon-eye-open"></span> ' . trans('misc.button.show') . '</a> '; $actions .= ' <a href="accounts/' . $account->id . '/edit" class="btn btn-xs btn-primary"><span class="glyphicon glyphicon-edit"></span> ' . trans('misc.button.edit') . '</a> '; if ($account->disabled) { $actions .= ' <a href="accounts/' . $account->id . '/enable' . '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-ok-circle"></span> ' . trans('misc.button.enable') . '</a> '; } else { $actions .= ' <a href="accounts/' . $account->id . '/disable' . '" class="btn btn-xs btn-warning"><span class="glyphicon glyphicon-ban-circle"></span> ' . trans('misc.button.disable') . '</a> '; } $actions .= \Form::button('<i class="glyphicon glyphicon-remove"></i> ' . trans('misc.button.delete'), ['type' => 'submit', 'class' => 'btn btn-danger btn-xs']); $actions .= \Form::close(); return $actions; })->make(true); }
/** * this should not be part of the setUp method because the database connection * has NOT been setUp properly at that moment. */ private function initDB() { Account::where('id', '!=', 1)->delete(); $this->accounts = factory(Account::class, 10)->create(); $this->name1 = $this->accounts->first()->name; $this->name2 = $this->accounts->get(1)->name; }
public function testCreateValid() { $brand = factory(Brand::class)->create(); Artisan::call('account:create', ['name' => 'test_dummy', 'brand_id' => $brand->id]); $output = Artisan::output(); $this->assertContains('The account has been created', $output); Account::where('name', 'test_dummy')->forceDelete(); $brand->forceDelete(); }
/** * @param $name * * @return mixed */ protected function findAccountByName($name) { $account = Account::where('id', $name)->orWhere('name', $name)->first(); if ($account === null) { $account = Account::find(['name' => 'Default'])->first(); if ($account === null) { $account = Account::all()->first(); } $this->info(sprintf("No account was found for given account name so '%s' was used", $account->name)); } return $account; }
/** * Execute the console command. * * @return boolean */ public function handle() { $generatedPassword = substr(md5(rand()), 0, 8); if (empty($this->option('password'))) { $this->info("Using auto generated password: {$generatedPassword}"); } if (empty($this->option('account'))) { $account = Account::where('name', '=', 'default')->first(); } else { $account = Account::where('name', '=', $this->option('account'))->first(); if (!is_object($account)) { $this->error("The account named {$this->option('account')} was not found"); return false; } } $user = new User(); $user->email = empty($this->option('email')) ? false : $this->option('email'); $user->password = empty($this->option('password')) ? $generatedPassword : $this->option('password'); $user->first_name = $this->option('firstname'); $user->last_name = $this->option('lastname'); $user->locale = $this->option('language'); $user->account_id = $account->id; $user->disabled = $this->option('disabled'); $validation = Validator::make($user->toArray(), User::createRules($user)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the user due to validation warnings'); return false; } if (!$user->save()) { $this->error('Failed to save the user into the database'); return false; } $this->info("The user {$this->option('email')} has been created"); return true; }
/** * {@inheritdoc}. */ protected function findWithCondition($filter) { return Account::where('name', 'like', "%{$filter}%")->get(); }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('user'))) { $this->warn('the required user argument was not passed, try --help'); return false; } $user = false; if (!is_object($user)) { $user = User::where('email', $this->option('user'))->first(); } if (!is_object($user)) { $user = User::find($this->option('user')); } if (!is_object($user)) { $this->error('Unable to find user with this criteria'); return false; } // Apply changes to the user object if (!empty($this->option('email'))) { $user->email = $this->option('email'); } if (!empty($this->option('password'))) { $user->password = $this->option('password'); } if (!empty($this->option('autopassword'))) { $generatedPassword = substr(md5(rand()), 0, 8); $this->info("Using auto generated password: {$generatedPassword}"); $user->password = $generatedPassword; } if (!empty($this->option('firstname'))) { $user->first_name = $this->option('firstname'); } if (!empty($this->option('lastname'))) { $user->last_name = $this->option('lastname'); } if (!empty($this->option('account'))) { $account = Account::where('name', '=', $this->option('account'))->first(); if (!is_object($account)) { $this->error("The account named {$this->option('account')} was not found"); return false; } $user->account_id = $account->id; } if (!empty($this->option('language'))) { $user->locale = $this->option('language'); } if (!empty($this->option('disable'))) { $user->disabled = true; } if (!empty($this->option('enable'))) { $user->disabled = false; } // Validate the changes $validation = Validator::make($user->toArray(), User::updateRules($user)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the user due to validation warnings'); return false; } // Save the object $user->save(); $this->info("User has been successfully updated"); return true; }
public function testModelFactory() { $account = factory(Account::class)->create(); $accountFromDB = Account::where('name', $account->name)->first(); $this->assertEquals($account->name, $accountFromDB->name); }
/** * {@inherit docs} */ protected function getCollectionWithArguments() { return Account::where("name", "like", "%" . $this->argument("account") . "%")->orWhere("id", $this->argument("account")); }
/** * {@inherit docs}. */ protected function getCollectionWithArguments() { return Account::where('name', 'like', '%' . $this->argument('account') . '%')->orWhere('id', $this->argument('account')); }