ask('Type in desired region'); $suggestions = Http::get('https://www.e-domizil.ch/api/v2/autocomplete?q='.$name.'&limit=6'); $options = []; if($suggestions->successful()){ $suggestionsArr = json_decode($suggestions->body(), 1); if(count($suggestionsArr['suggestions']) > 0){ foreach ($suggestionsArr['suggestions'] as $suggestion) { $options[$suggestion['id']] = $suggestion['fullTitle']; } $choice = $this->choice( 'Choose desired region', $options ); $id = $choice; $name = $options[$choice]; } } $region = Regions::create([ 'name' => $name ]); $this->info('New Region created '.$region); if(count($options) > 0){ $seed = Seed::create([ 'uri' => 'https://www.e-domizil.ch/search/'.$id.'?_format=json', 'region_id' => $region['id'] ]); $this->info('New Seed added '.$seed); } } }