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 e69de29..fe7d217 100644 Binary files a/skolehjem/laravel.sqlite and b/skolehjem/laravel.sqlite differ 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");