public function autocompleteBySettlementName() { $settlement = htmlentities(Input::get('settlement'), ENT_QUOTES, 'UTF-8', false); $name = htmlentities(Input::get('query'), ENT_QUOTES, 'UTF-8', false); $settlement = Settlement::where('name', 'LIKE', "{$settlement}%")->orWhere('name_en', 'LIKE', "{$settlement}%")->first(); if (!$settlement) { return ['results' => [], 'more' => false]; } $result = Office::where('city_id', $settlement->id)->whereNested(function ($query) use($name) { $query->where('name', 'LIKE', "%{$name}%")->orWhere('name_en', 'LIKE', "%{$name}%"); })->get(['id', 'bg' === App::getLocale() ? 'name' : 'name_en AS name']); return ['results' => $result, 'more' => false]; }
/** * Execute the console command. * * @return mixed * @codeCoverageIgnore */ public function handle() { $time = time(); DB::connection('econt')->disableQueryLog(); $this->comment(PHP_EOL . 'Starting...'); $this->comment(PHP_EOL . 'Importing zones and settlements... Please wait.'); Zone::whereRaw(1)->delete(); Settlement::whereRaw(1)->delete(); foreach (App::make('Econt')->zones() as $zone) { (new Zone())->import($zone); $zone_id = Arr::has($zone, 'id') ? Arr::get($zone, 'id') : 0; foreach (App::make('Econt')->settlements($zone_id) as $settlement) { if (!is_array($settlement)) { continue; } (new Settlement())->import($settlement); } } $this->comment(PHP_EOL . 'Zones and settlements imported successfully.'); $this->comment(PHP_EOL . 'Importing regions... Please wait.'); Region::whereRaw(1)->delete(); foreach (App::make('Econt')->regions() as $region) { (new Region())->import($region); } $this->comment(PHP_EOL . 'Regions imported successfully.' . PHP_EOL); $this->comment(PHP_EOL . 'Importing neighbourhoods... Please wait.'); Neighbourhood::whereRaw(1)->delete(); foreach (App::make('Econt')->neighbourhoods() as $region) { (new Neighbourhood())->import($region); } $this->comment(PHP_EOL . 'Neighbourhoods imported successfully.' . PHP_EOL); $this->comment(PHP_EOL . 'Importing streets... Please wait.'); Street::whereRaw(1)->delete(); foreach (App::make('Econt')->streets() as $region) { (new Street())->import($region); } $this->comment(PHP_EOL . 'Streets imported successfully.' . PHP_EOL); $this->comment(PHP_EOL . 'Importing offices... Please wait.'); Office::whereRaw(1)->delete(); foreach (App::make('Econt')->offices() as $region) { (new Office())->import($region); } $this->comment(PHP_EOL . 'Offices imported successfully.' . PHP_EOL); $this->comment(PHP_EOL . sprintf('Finished in %f minutes.', (time() - $time) / 60)); }
protected function _receiverCalc() { $receiver = new Receiver(); $receiver->city = Input::get('receiver.settlement'); $receiver->post_code = Input::get('receiver.post_code'); switch (Input::get('receiver.pickup')) { case 'office': $receiver->office_code = Office::find((int) Input::get('receiver.office'))->code; break; } return $receiver; }