proximity search added

This commit is contained in:
Benjamin Takats
2022-12-03 21:39:41 +01:00
parent 43b8d8a284
commit 4c49243af0
3 changed files with 101 additions and 12 deletions

View File

@@ -73,8 +73,16 @@ class CityTable extends DataTableComponent
->find($id);
$query = City::radius($city->latitude, $city->longitude, 100)
->where('id', '!=', $id);
$this->notification()
->success('Proximity Search', 'Found '.$query->count().' cities. '.$query->pluck('name')
->implode(', '));
return to_route('search.event', [
'#table',
'country' => $this->country,
'table' => [
'filters' => [
'stadt' => $query->pluck('name')
->push($city->name)
->implode(',')
],
]
]);
}
}

View File

@@ -2,25 +2,26 @@
namespace App\Http\Livewire\Tables;
use App\Models\Category;
use App\Models\Event;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;
class EventTable extends DataTableComponent
{
public string $country;
protected $model = Event::class;
public bool $viewingModal = false;
public $currentModal;
protected $model = Event::class;
public function configure(): void
{
$this
->setPrimaryKey('id')
->setDefaultSort('from', 'asc')
->setAdditionalSelects([
'course_id',
'venue_id',
@@ -41,6 +42,40 @@ class EventTable extends DataTableComponent
->setPerPage(50);
}
public function filters(): array
{
return [
TextFilter::make('Stadt')
->config([
'placeholder' => __('Suche Stadt'),
])
->filter(function (Builder $builder, string $value) {
if (str($value)->contains(',')) {
$builder
->whereHas('venue.city',
function ($query) use ($value) {
foreach (str($value)->explode(',') as $item) {
$query->orWhere('cities.name', 'ilike', "%$item%");
}
});
} else {
$builder->whereHas('venue.city',
fn($query) => $query->where('cities.name', 'ilike', "%$value%"));
}
}),
MultiSelectFilter::make('Art')
->options(
Category::query()
->pluck('name', 'id')
->toArray()
)
->filter(function (Builder $builder, array $values) {
$builder->whereHas('course.categories',
fn($query) => $query->whereIn('categories.id', $values));
}),
];
}
public function columns(): array
{
return [

View File

@@ -63,6 +63,18 @@ class DatabaseSeeder extends Seeder
'latitude' => 47.57143,
'longitude' => 10.70171,
]);
City::create([
'country_id' => 1,
'name' => 'Kempten',
'latitude' => 47.728569,
'longitude' => 10.315784,
]);
City::create([
'country_id' => 1,
'name' => 'Pfronten',
'latitude' => 47.582359,
'longitude' => 10.5598,
]);
City::create([
'country_id' => 2,
'name' => 'Wien',
@@ -77,8 +89,18 @@ class DatabaseSeeder extends Seeder
]);
Venue::create([
'city_id' => 1,
'name' => 'The Blue Studio Coworking',
'street' => 'Teststraße 12',
'name' => 'The Blue Studio Coworking (Füssen)',
'street' => 'Teststraße 1',
]);
Venue::create([
'city_id' => 2,
'name' => 'The Blue Studio Coworking (Kempten)',
'street' => 'Teststraße 2',
]);
Venue::create([
'city_id' => 3,
'name' => 'The Blue Studio Coworking (Pfronten)',
'street' => 'Teststraße 3',
]);
Lecturer::create([
'team_id' => 1,
@@ -97,6 +119,12 @@ class DatabaseSeeder extends Seeder
'lecturer_id' => 1,
'name' => 'Hands on Bitcoin',
]);
$course->categories()
->attach($category);
$course = Course::create([
'lecturer_id' => 1,
'name' => 'Bitcoin <> Crypto',
]);
$course->categories()
->attach($category);
Participant::create([
@@ -104,11 +132,29 @@ class DatabaseSeeder extends Seeder
'last_name' => 'Reher',
]);
Event::create([
'course_id' => 1,
'course_id' => 2,
'venue_id' => 1,
'link' => 'https://einundzwanzig.space',
'from' => now()->startOfDay(),
'to' => now()
'from' => now()->addDays(14)->startOfDay(),
'to' => now()->addDays(14)
->startOfDay()
->addHour(),
]);
Event::create([
'course_id' => 1,
'venue_id' => 2,
'link' => 'https://einundzwanzig.space',
'from' => now()->addDays(3)->startOfDay(),
'to' => now()->addDays(3)
->startOfDay()
->addHour(),
]);
Event::create([
'course_id' => 1,
'venue_id' => 3,
'link' => 'https://einundzwanzig.space',
'from' => now()->addDays(4)->startOfDay(),
'to' => now()->addDays(4)
->startOfDay()
->addHour(),
]);