Aktiviteter
+ {!! session()->get('eventunsubscribed') !!} + @if(!$userevents->isEmpty()) + @foreach($userevents as $userevent) + + @endforeach + @else +Du har ikke tilmeldt dig nogen aktiviteter!
+ @endif + Tilbage +diff --git a/skolehjem/app/Http/Controllers/UserEventController.php b/skolehjem/app/Http/Controllers/UserEventController.php index 001e730..55715fb 100644 --- a/skolehjem/app/Http/Controllers/UserEventController.php +++ b/skolehjem/app/Http/Controllers/UserEventController.php @@ -8,7 +8,17 @@ use Illuminate\Http\Response; class UserEventController extends Controller { + /** + * Update the specified resource in storage. + * + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function index() + { + $userevents = UserEvent::join('events', 'events.id', '=', 'user_events.event_id')->where('user_id', auth()->user()->id)->get(); + return Response::detect("events.yourevents", [ "userevents" => $userevents ]); + } /** * Update the specified resource in storage. @@ -20,12 +30,11 @@ class UserEventController extends Controller { // Get written data from events.index $data = $request->validate([ - "user_id" => "required|max:255", "event_id" => "required|max:255" ]); // Check the UserEvent table if there is a row that has the user_id AND the event_id - $getTableInfo = UserEvent::where('user_id', $request->user_id) + $getTableInfo = UserEvent::where('user_id', auth()->user()->id) ->where('event_id', $request->event_id)->get(); // If the row has both, then go back and show an error - Cause you're not allowed to be on the same event twice. @@ -34,8 +43,33 @@ class UserEventController extends Controller // If not, then it keeps going and saves and shows a success message $UserEvent = new UserEvent($data); + $UserEvent->user_id = auth()->user()->id; $UserEvent->save(); return redirect()->route("events.index")->with('signup#' . $request->event_id, '
Du er hermed tilmeldt denne aktivitet!
'); } + + /** + * Update the specified resource in storage. + * + * @param UserEvent $id + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function destroy($id) + { + // Check the UserEvent table if there is a row that has the user_id AND the event_id + //$UserEvent = UserEvent::find($eventid) + + $UserEvent = UserEvent::query()->where('user_id', "=", auth()->user()->id)->where('event_id', "=", $id); + + $UserEvent->delete(); + + $JoinedEvents = UserEvent::query()->join('events', 'events.id', '=', 'user_events.event_id')->where('user_id', "=", auth()->user()->id)->get(); + + return redirect()->route("userevents.index", [ "userevents" => $JoinedEvents ])->with('eventunsubscribed', 'Du har hermed afmeldt aktiviteten!
'); + } + + public function show() + { + } } diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index d363c54..647253f 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -61,11 +61,11 @@ class WashingReservationController extends Controller { $data = $request->validate([ "time" => "required", - "machine_id" => "required|unique:washing_reservations,machine_id,NULL,id,time,' . $request->time", - "user_id" => "required" + "machine_id" => "required|unique:washing_reservations,machine_id,NULL,id,time,' . $request->time" ]); $machineReservation = new WashingReservation($data); + $machineReservation->user_id = auth()->user()->id; $machineReservation->save(); $saved = $machineReservation->save(); diff --git a/skolehjem/resources/views/app/events/index.blade.php b/skolehjem/resources/views/app/events/index.blade.php index 43e03ac..a39a82f 100644 --- a/skolehjem/resources/views/app/events/index.blade.php +++ b/skolehjem/resources/views/app/events/index.blade.php @@ -12,7 +12,6 @@{{$event->date}}
{{$event->description}}
- {!! session()->get('error#' . $event->id) !!} {!! session()->get('signup#' . $event->id) !!} @@ -22,5 +21,6 @@ @elseDer er ingen aktiviteter!
@endif + Se Tilmeldte Aktiviteter @endsection diff --git a/skolehjem/resources/views/app/events/yourevents.blade.php b/skolehjem/resources/views/app/events/yourevents.blade.php new file mode 100644 index 0000000..1bc5edd --- /dev/null +++ b/skolehjem/resources/views/app/events/yourevents.blade.php @@ -0,0 +1,26 @@ +@extends("app.layout.base") +@section("title") + Aktiviteter +@endsection + +@section("content") +Du har ikke tilmeldt dig nogen aktiviteter!
+ @endif + Tilbage +