/** * @param $name * @return Domain|null */ private function findByName($name) { if (strlen($name) > 0) { return Domain::where("name", "like", '%' . $this->option("name"))->first(); } return null; }
public function testValidCreate() { $faker = Factory::create(); $domainName = $faker->domainName; Artisan::call('domain:create', ['name' => $domainName, 'contact_id' => Contact::all()->first()->id]); $this->assertContains('The domain has been created', Artisan::output()); Domain::where('name', $domainName)->forceDelete(); }
/** * {@inheritdoc}. */ protected function getValidator($model) { if (null !== $model) { $data = $this->getModelAsArrayForDirtyAttributes($model); $updateRules = $this->getUpdateRulesForDirtyAttributes(Domain::updateRules($model)); return Validator::make($data, $updateRules); } return false; }
static function byDomain($domainName) { $domain = Domain::where('name', '=', $domainName)->where('enabled', '=', true)->take(1)->get(); if (isset($domain[0])) { return $domain[0]->contact; } elseif (class_exists('AbuseIO::Custom::FindContact') === true && is_callable('\\AbuseIO\\Custom\\FindContact->byDomain') === true) { // Call custom function } else { return FindContact::undefined(); } }
/** * Return contact by Domain * @param string $domainName * @return object */ public static function byDomain($domain) { $result = Domain::where('name', '=', $domain)->where('enabled', '=', true)->take(1)->get(); if (isset($result[0])) { return $result[0]->contact; } $findContact = FindContact::getExternalResolver('domain', $domain); if (!empty($findContact)) { return $findContact; } return FindContact::undefined(); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { switch ($this->method) { case 'GET': break; case 'DELETE': break; case 'POST': return Domain::createRules(); case 'PUT': break; case 'PATCH': return Domain::updateRules($this); default: break; } return []; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('id'))) { $this->warn('The required id argument was not passed, try --help'); return false; } /** @var Domain|null $domain */ $domain = Domain::find($this->option('id')); if (null === $domain) { $this->error('Unable to find domain with this criteria'); return false; } if (!empty($this->option("contact"))) { /** @var User|null $user */ $user = User::find($this->option('contact')) ?: User::where('email', '=', $this->option("contact"))->first(); if (null === $user) { $this->error("Unable to find contact with this criteria"); return false; } $domain->contact()->associate($user); } if (!empty($this->option("name"))) { $domain->name = $this->option("name"); } if (!empty($this->option("enabled"))) { $domain->enabled = castStringToBool($this->option("enabled")); } $validation = Validator::make($domain->toArray(), Domain::updateRules($domain)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the domain due to validation warnings'); return false; } $domain->save(); $this->info("Domain has been successfully updated"); return true; }
/** * Return contact by Domain * * @param string $domain domain name * @return object */ public static function byDomain($domain) { // If local lookups are not preferred, then do the remote lookup first if (config('main.external.prefer_local') === false) { $findContact = FindContact::getExternalContact('domain', $domain); if (!empty($findContact)) { return $findContact; } } // Do a local lookup $result = Domain::where('name', '=', $domain)->where('enabled', '=', true)->take(1)->get(); if (isset($result[0])) { return $result[0]->contact; } // Do a remote lookup, if local lookups are preferred. Else skip this as this was already done. if (config('main.external.prefer_local') === true) { $findContact = FindContact::getExternalContact('domain', $domain); if (!empty($findContact)) { return $findContact; } } return FindContact::undefined(); }
/** * {@inheritdoc } */ protected function getObjectByArguments() { return Domain::find($this->argument("id")); }
public function testModelFactory() { $domain = factory(Domain::class)->create(); $domainFromDB = Domain::where('name', $domain->name)->first(); $this->assertEquals($domain->name, $domainFromDB->name); }
/** * {@inherit docs}. */ protected function getCollectionWithArguments() { return Domain::where('name', 'like', '%' . $this->argument('domain') . '%')->orWhere('id', $this->argument('domain')); }
/** * Remove the specified resource from storage. * @param int $id * @return Response */ public function destroy(Domain $domain) { $domain->delete(); return Redirect::route('admin.domains.index')->with('message', 'Domain has been deleted.'); }
/** * {@inheritdoc}. */ protected function findAll() { return Domain::all(); }
/** * {@inheritdoc}. */ protected function getValidator($model) { return Validator::make($model->toArray(), Domain::createRules()); }