From 0b72467b2158929f6cfa5c6c1a952c39329da9a3 Mon Sep 17 00:00:00 2001
From: Stephano Vogel
Date: Fri, 18 Oct 2024 15:20:48 +0200
Subject: [PATCH] Add Event Places to the Event creation page (#108)
* wip
* area and place (select-view)
* Event Creation additions
- Added searchable dropdown/select
- Added role check for StoreEventRequest
- Added EventPlace relationship to Event
* Lint fixes
---------
Co-authored-by: Yusef Aslan
---
app/Http/Controllers/EventController.php | 8 +-
app/Http/Requests/StoreEventRequest.php | 4 +-
app/Livewire/SearchableDropdown.php | 28 +++++++
app/Models/Area.php | 5 ++
app/Models/Event.php | 6 ++
app/Models/EventPlace.php | 5 ++
lang/de/messages.php | 1 +
.../views/components/event/card.blade.php | 4 +-
.../components/searchable-dropdown.blade.php | 79 +++++++++++++++++++
resources/views/components/textarea.blade.php | 2 +-
resources/views/events/create.blade.php | 13 +--
11 files changed, 144 insertions(+), 11 deletions(-)
create mode 100644 app/Livewire/SearchableDropdown.php
create mode 100644 resources/views/components/searchable-dropdown.blade.php
diff --git a/app/Http/Controllers/EventController.php b/app/Http/Controllers/EventController.php
index 73bbc1f..556c019 100644
--- a/app/Http/Controllers/EventController.php
+++ b/app/Http/Controllers/EventController.php
@@ -4,6 +4,7 @@
use App\Http\Requests\StoreEventRequest;
use App\Http\Requests\UpdateEventRequest;
+use App\Models\Area;
use App\Models\Event;
use Illuminate\Support\Facades\Auth;
@@ -24,7 +25,11 @@ public function index()
*/
public function create()
{
- return view('events.create');
+ return view('events.create', [
+ 'areas' => Area::with(['eventPlaces' => function ($query) {
+ $query->orderBy('name');
+ }])->orderBy('name')->get(),
+ ]);
}
/**
@@ -39,6 +44,7 @@ public function store(StoreEventRequest $request)
'organizer_id' => Auth::user()->organizer->id,
'starts_at' => $request->starts_at,
'ends_at' => $request->ends_at,
+ 'event_place_id' => $request->event_place,
]);
return redirect()->route('events.show', ['event' => $event]);
diff --git a/app/Http/Requests/StoreEventRequest.php b/app/Http/Requests/StoreEventRequest.php
index 1b58b32..f81257a 100644
--- a/app/Http/Requests/StoreEventRequest.php
+++ b/app/Http/Requests/StoreEventRequest.php
@@ -11,7 +11,7 @@ class StoreEventRequest extends FormRequest
*/
public function authorize(): bool
{
- return true;
+ return $this->user()->hasRole('Veranstalter');
}
/**
@@ -26,7 +26,7 @@ public function rules(): array
'description' => 'required|string|min:3|max:4096',
'event_type' => 'integer|in:event_types',
'event_category' => 'integer|in:event_categories',
- 'event_place' => 'integer|in:event_places',
+ 'event_place' => 'required',
'starts_at' => 'required|date',
'ends_at' => 'date|after:starts_at',
];
diff --git a/app/Livewire/SearchableDropdown.php b/app/Livewire/SearchableDropdown.php
new file mode 100644
index 0000000..d9a29c0
--- /dev/null
+++ b/app/Livewire/SearchableDropdown.php
@@ -0,0 +1,28 @@
+value = $value;
+ }
+
+ public function render()
+ {
+ return view('components.searchable-dropdown');
+ }
+}
diff --git a/app/Models/Area.php b/app/Models/Area.php
index b3b001e..e80e8f5 100644
--- a/app/Models/Area.php
+++ b/app/Models/Area.php
@@ -12,4 +12,9 @@ class Area extends Model
protected $fillable = ['id', 'name'];
public $timestamps = false;
+
+ public function eventPlaces()
+ {
+ return $this->hasMany(EventPlace::class);
+ }
}
diff --git a/app/Models/Event.php b/app/Models/Event.php
index e835f9f..5302b55 100644
--- a/app/Models/Event.php
+++ b/app/Models/Event.php
@@ -52,5 +52,11 @@ protected function casts(): array
'organizer_id',
'starts_at',
'ends_at',
+ 'event_place_id',
];
+
+ public function eventPlace(): \Illuminate\Database\Eloquent\Relations\HasOne
+ {
+ return $this->hasOne(EventPlace::class, 'id', 'event_place_id');
+ }
}
diff --git a/app/Models/EventPlace.php b/app/Models/EventPlace.php
index 383e64f..8acd4e1 100644
--- a/app/Models/EventPlace.php
+++ b/app/Models/EventPlace.php
@@ -12,4 +12,9 @@ class EventPlace extends Model
protected $fillable = ['area_id', 'name', 'zip_code'];
public $timestamps = false;
+
+ public function area()
+ {
+ return $this->belongsTo(Area::class);
+ }
}
diff --git a/lang/de/messages.php b/lang/de/messages.php
index 421e42c..41f9cad 100644
--- a/lang/de/messages.php
+++ b/lang/de/messages.php
@@ -24,6 +24,7 @@
'form' => [
'description' => 'Beschreibung',
'ends_at' => 'Ende',
+ 'place' => 'Ort',
'starts_at' => 'Beginn',
'submit' => 'Veranstaltung erstellen',
'title' => 'Name',
diff --git a/resources/views/components/event/card.blade.php b/resources/views/components/event/card.blade.php
index 6f6435d..2b9cb01 100644
--- a/resources/views/components/event/card.blade.php
+++ b/resources/views/components/event/card.blade.php
@@ -20,12 +20,12 @@
{{ $event->ends_at->format('D, d.m.Y H:i') }}
- München
+ {{ $event->eventPlace->name }}
- {{ random_int(1, 10) }} Teilnehmer
+ {{ random_int(1, 10) }} Teilnehmer
Kostenlos
diff --git a/resources/views/components/searchable-dropdown.blade.php b/resources/views/components/searchable-dropdown.blade.php
new file mode 100644
index 0000000..41f33de
--- /dev/null
+++ b/resources/views/components/searchable-dropdown.blade.php
@@ -0,0 +1,79 @@
+@props(['options', 'property', 'child-property', 'value' => ''])
+
+
diff --git a/resources/views/components/textarea.blade.php b/resources/views/components/textarea.blade.php
index 5623eb5..287f40c 100644
--- a/resources/views/components/textarea.blade.php
+++ b/resources/views/components/textarea.blade.php
@@ -1,4 +1,4 @@
@props(['disabled' => false])
-
\ No newline at end of file
+
diff --git a/resources/views/events/create.blade.php b/resources/views/events/create.blade.php
index 031f1b0..58c1e19 100644
--- a/resources/views/events/create.blade.php
+++ b/resources/views/events/create.blade.php
@@ -4,8 +4,6 @@
{{ __('messages.events.heading.create') }}
-
-
-
@error('ends_at') {{ $message }} @enderror
+
+
{{ __('messages.events.form.place') }}
+
+
@error('event_place') {{ $message }} @enderror
+
+
{{ __('messages.events.form.submit') }}
@@ -42,4 +45,4 @@
CANCEL
-
\ No newline at end of file
+