2020-07-28 06:44:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-07-28 08:13:44 +00:00
|
|
|
use App\UserEvent;
|
2020-07-28 06:44:25 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
|
|
|
class UserEventController extends Controller
|
|
|
|
{
|
2020-07-29 12:59:35 +00:00
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2020-08-03 09:17:36 +00:00
|
|
|
$userevents = UserEvent::join('events', 'events.id', '=', 'user_events.event_id')->orderBY('date' , 'asc')->where('user_id', auth()->user()->id)->get();
|
2020-07-28 06:44:25 +00:00
|
|
|
|
2020-07-29 12:59:35 +00:00
|
|
|
return Response::detect("events.yourevents", [ "userevents" => $userevents ]);
|
|
|
|
}
|
2020-07-28 06:44:25 +00:00
|
|
|
|
2020-07-29 13:28:21 +00:00
|
|
|
public function store() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-28 06:44:25 +00:00
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-07-29 13:28:21 +00:00
|
|
|
* @param UserEvent $eventid
|
2020-07-28 06:44:25 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
2020-07-28 08:13:44 +00:00
|
|
|
public function create(Request $request)
|
2020-07-28 06:44:25 +00:00
|
|
|
{
|
2020-07-28 08:13:44 +00:00
|
|
|
// Get written data from events.index
|
|
|
|
$data = $request->validate([
|
|
|
|
"event_id" => "required|max:255"
|
|
|
|
]);
|
2020-07-28 06:44:25 +00:00
|
|
|
|
2020-07-28 08:13:44 +00:00
|
|
|
// Check the UserEvent table if there is a row that has the user_id AND the event_id
|
2020-07-29 12:59:35 +00:00
|
|
|
$getTableInfo = UserEvent::where('user_id', auth()->user()->id)
|
2020-07-28 08:13:44 +00:00
|
|
|
->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, '<p class="text-center">Du har allerede tilmeldt dig denne Aktivitet!</p>');
|
|
|
|
|
|
|
|
// If not, then it keeps going and saves and shows a success message
|
|
|
|
$UserEvent = new UserEvent($data);
|
2020-07-29 12:59:35 +00:00
|
|
|
$UserEvent->user_id = auth()->user()->id;
|
2020-07-28 08:13:44 +00:00
|
|
|
$UserEvent->save();
|
|
|
|
|
|
|
|
return redirect()->route("events.index")->with('signup#' . $request->event_id, '<p class="text-center">Du er hermed tilmeldt denne aktivitet!</p>');
|
2020-07-28 06:44:25 +00:00
|
|
|
}
|
2020-07-29 12:59:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2020-08-03 09:17:36 +00:00
|
|
|
return redirect()->route("userevents.index", [ "userevents" => $JoinedEvents ])->with('eventunsubscribed', '<p class="text-center">Du er hermed afmeldt aktiviteten!</p>');
|
2020-07-29 12:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function show()
|
|
|
|
{
|
|
|
|
}
|
2020-07-29 13:28:21 +00:00
|
|
|
|
|
|
|
public function edit() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update() {
|
|
|
|
|
|
|
|
}
|
2020-07-28 06:44:25 +00:00
|
|
|
}
|