From 07405d575d3b137738847a7c28b5002ef3e40450 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 15 Jun 2020 08:59:15 +0200 Subject: [PATCH] Added more routes. --- .../app/Http/Controllers/UserController.php | 11 ++++ .../WashingReservationController.php | 60 +++++++++++++----- skolehjem/app/Http/Kernel.php | 4 ++ .../app/Providers/RouteServiceProvider.php | 2 +- skolehjem/laravel.sqlite | Bin 0 -> 118784 bytes .../resources/views/user/create.blade.php | 27 ++++++++ skolehjem/routes/web.php | 5 +- 7 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 skolehjem/resources/views/user/create.blade.php diff --git a/skolehjem/app/Http/Controllers/UserController.php b/skolehjem/app/Http/Controllers/UserController.php index 4f1c783..1b9a79f 100644 --- a/skolehjem/app/Http/Controllers/UserController.php +++ b/skolehjem/app/Http/Controllers/UserController.php @@ -9,6 +9,17 @@ use Illuminate\Support\Facades\Auth; class UserController extends Controller { + public function __construct() + { + $this->middleware([ "auth" ])->only("logout"); + $this->middleware([ "guest" ])->only("login"); + + $this->middleware([ "permission:user.list", "role:admin" ])->only("index"); + $this->middleware([ "permission:user.show", "role:admin" ])->only("show"); + $this->middleware([ "permission:user.edit", "role:admin" ])->only([ "edit", "update" ]); + $this->middleware([ "permission:user.delete", "role:admin" ])->only("delete"); + } + /** * Display a listing of the resource. * diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index ec89105..23ee6ee 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -3,60 +3,75 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\WashingReservation; class WashingReservationController extends Controller { /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @param Request $request + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function index() + public function index(Request $request) { - // + $reservations = WashingReservation::query()->paginate($request->query("page", 1)); + + return view("washing-reservation.index"); } /** * Show the form for creating a new resource. * - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function create() { - // + return view("washing-reservation.create"); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function store(Request $request) { - // + $data = $request->validate([ + "time" => "required" + ]); + + $machineReservation = new WashingReservation($data); + $machineReservation->save(); + + return view("washing-reservation.store"); } /** * Display the specified resource. * * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show($id) { - // + $machineReservation = WashingReservation::find($id); + + return view("washing-reservation.show", [ + "machineReservation" => $machineReservation + ]); } /** * Show the form for editing the specified resource. * * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function edit($id) { - // + return view("washing-reservation.edit"); } /** @@ -64,21 +79,36 @@ class WashingReservationController extends Controller * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function update(Request $request, $id) { - // + $data = $request->validate([ + "time" => "required" + ]); + + $machineReservation = WashingReservation::find($id); + + $machineReservation->update($data); + + $machineReservation->save(); + + return view("washing-reservation.edit", [ + "washingReservation" => $machineReservation + ]); } /** * Remove the specified resource from storage. * * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function destroy($id) { - // + $machineReservation = WashingReservation::find($id); + $machineReservation->delete(); + + return view("washing-reservation.delete"); } } diff --git a/skolehjem/app/Http/Kernel.php b/skolehjem/app/Http/Kernel.php index 36ced13..6a08dd6 100644 --- a/skolehjem/app/Http/Kernel.php +++ b/skolehjem/app/Http/Kernel.php @@ -63,5 +63,9 @@ class Kernel extends HttpKernel 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + + 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class, + 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class, + 'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class, ]; } diff --git a/skolehjem/app/Providers/RouteServiceProvider.php b/skolehjem/app/Providers/RouteServiceProvider.php index 540d17b..d60d77d 100644 --- a/skolehjem/app/Providers/RouteServiceProvider.php +++ b/skolehjem/app/Providers/RouteServiceProvider.php @@ -72,7 +72,7 @@ class RouteServiceProvider extends ServiceProvider */ protected function mapApiRoutes() { - Route::prefix('api') + Route::prefix('api/v1') ->middleware('api') ->namespace($this->namespace) ->group(base_path('routes/api.php')); diff --git a/skolehjem/laravel.sqlite b/skolehjem/laravel.sqlite index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..fe7d217d5254f9dd2d4e6186525f7d8eba63761b 100644 GIT binary patch literal 118784 zcmeI)&2QW09S3mIkwy7cd25)Y3&POd63$L1IdPp}DYm?5h0!LB6B}rd2E-%jk<416 z6q0h{Ls3vpciUmuA247*(MyXRwjO%fdFZi+0X-Kx6$5t94tt)5dLe1bHI#Hi<*(7Y z6rcCc^Aq_zq|y7U?^qtyDh;PjJnfQnSdwMw*P13t(j5Eu4EwkHbAlbDx*yno<#67I6REeyK1+?sUrFC( zJ|9%w3!V4hKdz`tOLF_6M~XH2gt!})T{Ru*QfG^JR>O9a&b@N;Ug7#$L0h|iFV3UK!4z)|v)k3Yfx(FIWYuH+u)+qZHmWW#- zWxBw>j{WMo%|J2t3F+ZZKX7Jf6cMiPmCN+~X9_dWi%AH$<_cVRq)#w~Do}Eu@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|fB*y_009U<;2;TL z|9_BX8)Jn41Rwwb2tWV=5P$##AOL}bDlo|he)yn{9^-}p1Rwwb2tWV=5P$##AOHaf I91MZ~0;oS^<^TWy literal 0 HcmV?d00001 diff --git a/skolehjem/resources/views/user/create.blade.php b/skolehjem/resources/views/user/create.blade.php new file mode 100644 index 0000000..ea07ef6 --- /dev/null +++ b/skolehjem/resources/views/user/create.blade.php @@ -0,0 +1,27 @@ +@extends('layout.base') + +@section("title") + Opret Bruger +@endsection + +@section('content') +
+
+ @csrf + + + + + + + + + + + + + + +
+
+@endsection diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index a2dcba3..3b8f92a 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -18,7 +18,8 @@ use Illuminate\Support\Facades\Route; //}); Route::middleware(["auth"])->group(function () { - + Route::resource("washing-machines", "WashingMachineController"); + Route::resource("washing-reservations", "WashingReservationController"); }); Route::get("/", "RootController@index")->name("root.index"); @@ -26,3 +27,5 @@ Route::get("/", "RootController@index")->name("root.index"); Route::get("/login", "UserController@login")->name("user.login"); Route::get("/logout", "UserController@logout")->name("user.logout"); + +Route::resource("users", "UserController");