diff --git a/app/Http/Controllers/Admin/EventController.php b/app/Http/Controllers/Admin/EventController.php index f39f0ba..e75f1df 100644 --- a/app/Http/Controllers/Admin/EventController.php +++ b/app/Http/Controllers/Admin/EventController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Event; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use function abort; use function compact; class EventController extends Controller @@ -13,4 +15,25 @@ class EventController extends Controller $events = Event::all(); return view('admin.event.index',compact('events')); } + + public function store(Request $request) + { + if(! Auth::user()->is_admin) abort(403); + request()->validate([ + 'name' => ['required', 'unique:events,name'], + ]); + + Event::create([ + 'name' => request('name'), + ]); + + return redirect()->route('admin.events.index')->with('success','Event created successfully'); + } + + public function destroy(Request $request, Event $event) + { + if(! Auth::user()->is_admin) abort(403); + $event->delete(); + return redirect()->route('admin.events.index')->with('success','Event deleted successfully'); + } } diff --git a/app/Models/Event.php b/app/Models/Event.php index aaba68a..f904010 100644 --- a/app/Models/Event.php +++ b/app/Models/Event.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; class Event extends Model { use HasFactory; + protected $guarded =[]; public function auditions(): HasMany { diff --git a/resources/views/admin/event/index-help-modal.blade.php b/resources/views/admin/event/index-help-modal.blade.php new file mode 100644 index 0000000..bdcb800 --- /dev/null +++ b/resources/views/admin/event/index-help-modal.blade.php @@ -0,0 +1,14 @@ + + About Events in AuditionAdmin + + diff --git a/resources/views/admin/event/index.blade.php b/resources/views/admin/event/index.blade.php index 615e27c..7189d22 100644 --- a/resources/views/admin/event/index.blade.php +++ b/resources/views/admin/event/index.blade.php @@ -4,36 +4,40 @@ Manage Events - - About Events in AuditionAdmin -
    - {{-- move help text to a popout modal --}} -
  • Events generally refer to the performance for a group of auditions
  • -
  • Every audition is assigned to one event
  • -
  • An event cannot be deleted without first deleting all of its auditions
  • -
  • Students will not be allowed to be seated in multiple auditions for the same event
  • -
  • If no student will ever be able to accept more than one seat, all auditions should be in one event
  • -
  • If you have, for example, concert bands and jazz bands that perform at different times, and a student can make both, you should create the concert auditions in one event, and the jazz auditions in another event.
  • -
-
+ @include('admin.event.index-help-modal')
- - -
- - @foreach($events as $event) - -
- {{ $event->name }} , {{ $event->auditions()->count() }} Auditions -
-
- @endforeach - {{-- The final row will allow for the creation of an event --}} - - - -
+ + + @foreach($events as $event) + + {{ $event->name }}, {{ $event->auditions()->count() }} Auditions + +   + @if($event->auditions()->count() == 0) +
+ @csrf + @method('DELETE') + +
+ @endif +
+ + @endforeach +
+ + + + + + + + Create + + + + +
diff --git a/resources/views/components/help-modal.blade.php b/resources/views/components/help-modal.blade.php index 8dbf181..4ee63de 100644 --- a/resources/views/components/help-modal.blade.php +++ b/resources/views/components/help-modal.blade.php @@ -14,7 +14,7 @@
prefix('admin/')->gr // Admin Event Routes Route::prefix('events')->controller(\App\Http\Controllers\Admin\EventController::class)->group(function() { - Route::get('/','index'); + Route::get('/','index')->name('admin.events.index'); + Route::post('/','store')->name('admin.events.store'); + Route::delete('/{event}','destroy')->name('admin.events.destroy'); }); // Admin Rooms Routes