You are now able to remove people who have signed up for events - With routing etc.

This commit is contained in:
Anders 2020-07-28 14:54:19 +02:00
parent cf533bb69f
commit 556e6cf25a
6 changed files with 144 additions and 4 deletions

6
.idea/encodings.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/skolehjem/public/images/icons/eye-dark.svg" charset="UTF-8" />
</component>
</project>

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Event; use App\Event;
use App\UserEvent;
use App\User; use App\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
@ -87,6 +88,23 @@ class EventController extends Controller
return Response::detect("events.show", [ "event" => $id ]); return Response::detect("events.show", [ "event" => $id ]);
} }
/**
* Display signups for event.
*
* @param int $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function signups(Request $request)
{
// Find every event you have clicked on. And find all users to that event, and the event name itself.
$events = UserEvent::join('users', 'users.id', '=', 'user_events.user_id')->join('events', 'events.id', '=', 'user_events.event_id')->where('event_id', $request->event)->get();
if (count($events) == 0)
$events = Event::where('id', $request->event)->get();
return Response::detect("events.signups", [ "events" => $events ]);
}
/** /**
* Show the form for editing the specified resource.- * Show the form for editing the specified resource.-
* *
@ -130,11 +148,20 @@ class EventController extends Controller
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Exception * @throws \Exception
*/ */
public function destroy($id) public function destroy(Request $request, $id)
{ {
$event = Event::find($id); if ($request->signup != null) { // If input signup is not empty, which has been set when you look at the individuel signup, then delete the user who have signed up for the event
$event->delete(); $UserEvent = UserEvent::where('user_id', $request->signup)->where('event_id', $id);
return redirect()->route("events.index"); $UserEvent->delete();
return redirect()->route("events.signups", [ "event" => $id ]);
} else { // Else if you are deleting an event. Then delete all the sign ups AND the event
$UserEvent = UserEvent::where('event_id', $id);
$UserEvent->delete();
$event = Event::find($id);
$event->delete();
return redirect()->route("events.index");
}
} }

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="windows-1252"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="511.626px" height="511.626px" viewBox="0 0 511.626 511.626" style="enable-background:new 0 0 511.626 511.626;" xml:space="preserve">
<style>#Capa_1{fill:#000;}</style>
<g>
<path d="M505.918,236.117c-26.651-43.587-62.485-78.609-107.497-105.065c-45.015-26.457-92.549-39.687-142.608-39.687 c-50.059,0-97.595,13.225-142.61,39.687C68.187,157.508,32.355,192.53,5.708,236.117C1.903,242.778,0,249.345,0,255.818 c0,6.473,1.903,13.04,5.708,19.699c26.647,43.589,62.479,78.614,107.495,105.064c45.015,26.46,92.551,39.68,142.61,39.68 c50.06,0,97.594-13.176,142.608-39.536c45.012-26.361,80.852-61.432,107.497-105.208c3.806-6.659,5.708-13.223,5.708-19.699 C511.626,249.345,509.724,242.778,505.918,236.117z M194.568,158.03c17.034-17.034,37.447-25.554,61.242-25.554 c3.805,0,7.043,1.336,9.709,3.999c2.662,2.664,4,5.901,4,9.707c0,3.809-1.338,7.044-3.994,9.704 c-2.662,2.667-5.902,3.999-9.708,3.999c-16.368,0-30.362,5.808-41.971,17.416c-11.613,11.615-17.416,25.603-17.416,41.971 c0,3.811-1.336,7.044-3.999,9.71c-2.667,2.668-5.901,3.999-9.707,3.999c-3.809,0-7.044-1.334-9.71-3.999 c-2.667-2.666-3.999-5.903-3.999-9.71C169.015,195.482,177.535,175.065,194.568,158.03z M379.867,349.04 c-38.164,23.12-79.514,34.687-124.054,34.687c-44.539,0-85.889-11.56-124.051-34.687s-69.901-54.2-95.215-93.222 c28.931-44.921,65.19-78.518,108.777-100.783c-11.61,19.792-17.417,41.207-17.417,64.236c0,35.216,12.517,65.329,37.544,90.362 s55.151,37.544,90.362,37.544c35.214,0,65.329-12.518,90.362-37.544s37.545-55.146,37.545-90.362 c0-23.029-5.808-44.447-17.419-64.236c43.585,22.265,79.846,55.865,108.776,100.783C449.767,294.84,418.031,325.913,379.867,349.04 z"/>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -24,6 +24,7 @@
<th>Event Navn</th> <th>Event Navn</th>
<th>Event Beskrivelse</th> <th>Event Beskrivelse</th>
<th>Event Dato</th> <th>Event Dato</th>
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/eye.svg') }}" alt="Update"></th>
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/pencil.svg') }}" alt="Update"></th> <th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/pencil.svg') }}" alt="Update"></th>
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/trashcan.svg') }}" alt="Delete"></th> <th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/trashcan.svg') }}" alt="Delete"></th>
</tr> </tr>
@ -32,6 +33,7 @@
<td>{{ $event->name }}</td> <td>{{ $event->name }}</td>
<td>{{ $event->description }}</td> <td>{{ $event->description }}</td>
<td>{{ $event->date }}</td> <td>{{ $event->date }}</td>
<td><a href="{{ route("events.signups", [ "event" => $event ]) }}"><img class="w-100" src="{{ asset('/images/icons/eye-dark.svg') }}" alt="Update"></a></td>
<td><a href="{{ route("events.edit", [ "event" => $event ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td> <td><a href="{{ route("events.edit", [ "event" => $event ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
<td><form method="post" action="{{ route("events.destroy", [ "event" => $event ]) }}" class="w-100 nostyle"> <td><form method="post" action="{{ route("events.destroy", [ "event" => $event ]) }}" class="w-100 nostyle">
@csrf @csrf

View File

@ -0,0 +1,65 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Events - Tilmeldte
@endsection
@section("path")
<a href="{{ route("events.index") }}" class="text-white">Vis Events</a> / <a href="" class="text-white">Vis Tilmeldte - {{ $events[0]->name }}</a> /
@endsection
@section("content")
<div class="row align-items-center">
<form method="post" action="{{ route("events.store") }}">
@csrf
<input type="text" class="form-controller" id="search" name="search" placeholder="Søg på Evt Navn, Evt Dato"></input>
</form>
</div>
<table class="tbl mt-2">
<tr>
<th>Tilmeldtes Fornavn</th>
<th>Tilmeldtes Efternavn</th>
<th>Tilmeldtes Tlf Nr</th>
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/trashcan.svg') }}" alt="Delete"></th>
</tr>
@foreach($events as $event)
@if ($event->name_first != null && $event->name_last != null && $event->phone != null && $event->event_id != null && $event->user_id != null)
<tr>
<td>{{ $event->name_first }}</td>
<td>{{ $event->name_last }}</td>
<td>{{ $event->phone }}</td>
<td><form method="post" action="{{ route("events.destroy", [ "event" => $event->event_id ]) }}" class="w-100 nostyle">
@csrf
@method("delete")
<button name="signup" value="{{ $event->user_id }}" class="w-100 nostyle" onclick="return confirm('Are you sure you want to delete?');" type="submit"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></button>
</form>
</td>
</tr>
@endif
@endforeach
</table>
<script>
$('#search').on('keyup', function () {
$value = $(this).val();
$.ajax({
type: 'get',
url: '{{route('events.search')}}',
data: {'search':$value},
success:function (data) {
$('tbody').html(data);
console.log(data);
},
error:function (data) {
console.log(data);
}
});
})
</script>
@endsection

View File

@ -29,6 +29,7 @@ Route::get("/account", "UserController@account")->name("users.account");
Route::get("/account/edit", "UserController@accountedit")->name("users.accountedit"); Route::get("/account/edit", "UserController@accountedit")->name("users.accountedit");
Route::get("/account/editpass", "UserController@accounteditpass")->name("users.accounteditpass"); Route::get("/account/editpass", "UserController@accounteditpass")->name("users.accounteditpass");
Route::post("/account/update", "UserController@update")->name("users.accountupdate"); Route::post("/account/update", "UserController@update")->name("users.accountupdate");
Route::get("/events/signups", "EventController@signups")->name("events.signups");
Route::get("phones", "PhoneController@index")->name("phones.index"); Route::get("phones", "PhoneController@index")->name("phones.index");
Route::get("/contactsapi", "ContactController@search")->name("contacts.search"); Route::get("/contactsapi", "ContactController@search")->name("contacts.search");
Route::get("/eventsapi", "EventController@search")->name("events.search"); Route::get("/eventsapi", "EventController@search")->name("events.search");