vector maps coordinates added

This commit is contained in:
Benjamin Takats
2022-12-13 20:17:51 +01:00
parent 26c699ab1a
commit 71addfcd62
7 changed files with 1454 additions and 23 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Console\Commands\Database;
use App\Models\City;
use App\Models\Country;
use App\Models\Meetup;
use Illuminate\Console\Command;
class ImportGithubMeetups extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'import:meetups';
/**
* The console command description.
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
* @return int
*/
public function handle()
{
$meetups = json_decode(file_get_contents(config_path('meetups/github.json')), true, 512, JSON_THROW_ON_ERROR);
foreach ($meetups as $meetup) {
$city = City::updateOrCreate([
'name' => $meetup['city'],
], [
'country_id' => Country::firstOrCreate([
'code' => str($meetup['country'])
->lower()
->toString()
], ['name' => $meetup['country']])->id,
'longitude' => $meetup['longitude'],
'latitude' => $meetup['latitude'],
]);
$meetup = Meetup::updateOrCreate(
['name' => $meetup['name']],
[
'city_id' => $city->id,
'link' => $meetup['url'],
]);
}
return Command::SUCCESS;
}
}

View File

@@ -3,13 +3,29 @@
namespace App\Http\Livewire\Meetup;
use App\Models\Country;
use App\Models\Meetup;
use Livewire\Component;
class MeetupTable extends Component
{
public Country $country;
public function render()
{
return view('livewire.meetup.meetup-table');
// let markers = [{name: 'VAK', coords: [50.0091294, 9.0371812], status: 'closed', offsets: [0, 2]}];
return view('livewire.meetup.meetup-table', [
'markers' => Meetup::query()
->with([
'city.country',
])
->whereHas('city.country',
fn($query) => $query->where('countries.code', $this->country->code))
->get()
->map(fn($meetup) => [
'name' => $meetup->name,
'coords' => [$meetup->city->latitude, $meetup->city->longitude],
])
]);
}
}