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) ->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. if (count($getTableInfo) > 0) return redirect()->route("events.index")->with('error#' . $request->event_id, '
Du har allerede tilmeldt dig denne Aktivitet!
'); // If not, then it keeps going and saves and shows a success message $UserEvent = new UserEvent($data); $UserEvent->save(); return redirect()->route("events.index")->with('signup#' . $request->event_id, 'Du er hermed tilmeldt denne aktivitet!
'); } }