From 9d757dc536148e5af1a4edee3ec1c14c6b773091 Mon Sep 17 00:00:00 2001 From: frederikpyt Date: Wed, 1 Jul 2020 11:38:09 +0200 Subject: [PATCH] Fixed washing machine reservation, creation, edit and deletion --- .../WashingReservationController.php | 43 ++++++++++++------- skolehjem/app/WashingReservation.php | 4 +- ..._08_085447_create_washing_reservations.php | 2 + .../washing-reservations/create.blade.php | 20 ++++----- .../admin/washing-reservations/edit.blade.php | 26 ++++++----- .../washing-reservations/index.blade.php | 14 +++--- .../washing-reservations/update.blade.php | 6 +-- 7 files changed, 66 insertions(+), 49 deletions(-) diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index 1063930..7b691cd 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -2,10 +2,15 @@ namespace App\Http\Controllers; +use App\WashingMachine; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Http\Response; use App\WashingReservation; +use Illuminate\View\View; class WashingReservationController extends Controller { @@ -24,11 +29,11 @@ class WashingReservationController extends Controller * Display a listing of the resource. * * @param Request $request - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Application|Factory|View */ public function index(Request $request) { - $reservations = WashingReservation::query()->paginate($request->query("page", 1)); + $reservations = WashingReservation::query()->paginate($request->query("limit", 20)); return Response::detect("washing-reservations.index", [ "reservations" => $reservations]); } @@ -36,23 +41,25 @@ class WashingReservationController extends Controller /** * Show the form for creating a new resource. * - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Application|Factory|View */ public function create() { - return Response::detect("washing-reservations.create"); + $machines = WashingMachine::all(); + return Response::detect("washing-reservations.create", [ 'machines' => $machines ]); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Application|Factory|View */ public function store(Request $request) { $data = $request->validate([ - "time" => "required" + "time" => "required", + "machine" => "required" ]); $machineReservation = new WashingReservation($data); @@ -65,7 +72,7 @@ class WashingReservationController extends Controller * Display the specified resource. * * @param int $id - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Application|Factory|View */ public function show($id) { @@ -80,11 +87,14 @@ class WashingReservationController extends Controller * Show the form for editing the specified resource. * * @param int $id - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Application|Factory|View */ public function edit($id) { - return Response::detect("washing-reservations.edit"); + $reservation = WashingReservation::query()->find($id); + $machines = WashingMachine::all(); + + return Response::detect("washing-reservations.edit", ['washing_reservation' => $reservation, 'machines' => $machines ]); } /** @@ -92,12 +102,13 @@ class WashingReservationController extends Controller * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Application|Factory|View */ public function update(Request $request, $id) { $data = $request->validate([ - "time" => "required" + "time" => "required", + "machine" => "required" ]); $machineReservation = WashingReservation::find($id); @@ -106,8 +117,8 @@ class WashingReservationController extends Controller $machineReservation->save(); - return Response::detect("washing-reservations.edit", [ - "washingReservation" => $machineReservation + return Response::detect("washing-reservations.update", [ + "washing_reservation" => $machineReservation ]); } @@ -115,13 +126,15 @@ class WashingReservationController extends Controller * Remove the specified resource from storage. * * @param int $id - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return RedirectResponse */ public function destroy($id) { $machineReservation = WashingReservation::find($id); $machineReservation->delete(); - return Response::detect("washing-reservations.delete"); + $reservations = WashingReservation::query()->paginate( 20); + + return redirect()->route("washing-reservations.index", [ "reservations" => $reservations]); } } diff --git a/skolehjem/app/WashingReservation.php b/skolehjem/app/WashingReservation.php index fe15a23..3925ecc 100644 --- a/skolehjem/app/WashingReservation.php +++ b/skolehjem/app/WashingReservation.php @@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model; class WashingReservation extends Model { - // + protected $fillable = [ + 'time', 'machine' + ]; } diff --git a/skolehjem/database/migrations/2020_06_08_085447_create_washing_reservations.php b/skolehjem/database/migrations/2020_06_08_085447_create_washing_reservations.php index e732b55..482ddd7 100644 --- a/skolehjem/database/migrations/2020_06_08_085447_create_washing_reservations.php +++ b/skolehjem/database/migrations/2020_06_08_085447_create_washing_reservations.php @@ -17,6 +17,8 @@ class CreateWashingReservations extends Migration $table->id(); $table->timestamp("time"); $table->timestamps(); + $table->unsignedBigInteger('machine'); + $table->foreign("machine")->references('id')->on('washing_machines'); }); } diff --git a/skolehjem/resources/views/admin/washing-reservations/create.blade.php b/skolehjem/resources/views/admin/washing-reservations/create.blade.php index 01d38ad..fb0308a 100644 --- a/skolehjem/resources/views/admin/washing-reservations/create.blade.php +++ b/skolehjem/resources/views/admin/washing-reservations/create.blade.php @@ -6,21 +6,21 @@ @endsection @section("path") - Opret Vaske Reservationer / + Opret Vaskemaskine Reservation / @endsection @section("content") -

Opret Booking:

+

Opret Reservation:

@csrf - - - - - - - + +
diff --git a/skolehjem/resources/views/admin/washing-reservations/edit.blade.php b/skolehjem/resources/views/admin/washing-reservations/edit.blade.php index 66e0edb..c1a2d98 100644 --- a/skolehjem/resources/views/admin/washing-reservations/edit.blade.php +++ b/skolehjem/resources/views/admin/washing-reservations/edit.blade.php @@ -6,22 +6,26 @@ @endsection @section("path") - Rediger Vaske Reservationer / + Rediger Vaske Reservationer / @endsection @section("content")

Rediger Booking:

-
+ @csrf - - - - - - - - + +
diff --git a/skolehjem/resources/views/admin/washing-reservations/index.blade.php b/skolehjem/resources/views/admin/washing-reservations/index.blade.php index 46939c3..2100b13 100644 --- a/skolehjem/resources/views/admin/washing-reservations/index.blade.php +++ b/skolehjem/resources/views/admin/washing-reservations/index.blade.php @@ -15,21 +15,17 @@ - - - + @foreach($reservations as $reservation) - - - - - - + + +
FornavnEfternavnTlf nr VaskemaskineTime Update Delete
{Fornavn}{Efternavn}{Tlf Nr}{Vaskemaskine Nr.}Update
+
{{ \App\WashingMachine::query()->find($reservation->machine)->name }}{{ $reservation->time }}Update @csrf @method("delete") diff --git a/skolehjem/resources/views/admin/washing-reservations/update.blade.php b/skolehjem/resources/views/admin/washing-reservations/update.blade.php index f890995..9cbf817 100644 --- a/skolehjem/resources/views/admin/washing-reservations/update.blade.php +++ b/skolehjem/resources/views/admin/washing-reservations/update.blade.php @@ -2,13 +2,13 @@ @extends("admin.layout.header") @section("title") - Vaske Reservationer - Rediger + Vaskemaskine Reservationer - Rediger @endsection @section("path") - Rediger Vaske Reservationer / + Rediger Vaskemaskine Reservationer / @endsection @section("content") - Din Vaske Reservationer blev (ikke) redigeret. + Din Vaskemaskine Reservationer blev (ikke) redigeret. @endsection