diff --git a/skolehjem/app/Http/Controllers/ResourceCategoryController.php b/skolehjem/app/Http/Controllers/ResourceCategoryController.php index eec6519..657c6ec 100644 --- a/skolehjem/app/Http/Controllers/ResourceCategoryController.php +++ b/skolehjem/app/Http/Controllers/ResourceCategoryController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\ResourceCategory; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -23,9 +24,11 @@ class ResourceCategoryController extends Controller * * @return \Illuminate\Http\Response */ - public function index() + public function index(Request $request) { - // + $categories = ResourceCategory::query()->paginate($request->input("limit", 20)); + + return Response::detect("resource-categories.index", ["category"=> $categories]); } /** @@ -35,7 +38,7 @@ class ResourceCategoryController extends Controller */ public function create() { - // + return Response::detect("resource-categories.create"); } /** @@ -46,7 +49,15 @@ class ResourceCategoryController extends Controller */ public function store(Request $request) { - // + $requestBody = $request->validate([ + "name" => "unique|required|max:255", + "description" => "required|max:255", + "slug" => "unique|required|max:255" + ]); + $category = new ResourceCategory($requestBody); + $category->save(); + + return Response::detect("resource-categories.store"); } /** @@ -55,9 +66,9 @@ class ResourceCategoryController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function show($id) + public function show(ResourceCategory $id) { - // + return Response::detect("resource-categories.show", ["category" => $id]); } /** @@ -68,7 +79,8 @@ class ResourceCategoryController extends Controller */ public function edit($id) { - // + $category = ResourceCategory::find($id); + return Response::detect("resource-categories.edit", ["category" => $category]); } /** @@ -80,7 +92,13 @@ class ResourceCategoryController extends Controller */ public function update(Request $request, $id) { - // + $data = $request->all(); + + $category = ResourceCategory::find($id); + $category->update($data); + $category->save(); + + return Response::detect("resource-categories.update", ["category" => $category]); } /** @@ -91,6 +109,8 @@ class ResourceCategoryController extends Controller */ public function destroy($id) { - // + $category = ResourceCategory::find($id); + $category->delete(); + return redirect()->route("resource-categories.index"); } } diff --git a/skolehjem/database/migrations/2020_07_01_064330_create_resource_categories.php b/skolehjem/database/migrations/2020_07_01_064330_create_resource_categories.php new file mode 100644 index 0000000..290931b --- /dev/null +++ b/skolehjem/database/migrations/2020_07_01_064330_create_resource_categories.php @@ -0,0 +1,34 @@ +id(); + $table->string("name")->unique(); + $table->text("description"); + $table->string("slug")->unique(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('resource_categories'); + } +} diff --git a/skolehjem/resources/views/admin/resource-categories/create.blade.php b/skolehjem/resources/views/admin/resource-categories/create.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/skolehjem/resources/views/admin/resource-categories/delete.blade.php b/skolehjem/resources/views/admin/resource-categories/delete.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/skolehjem/resources/views/admin/resource-categories/edit.blade.php b/skolehjem/resources/views/admin/resource-categories/edit.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/skolehjem/resources/views/admin/resource-categories/index.blade.php b/skolehjem/resources/views/admin/resource-categories/index.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/skolehjem/resources/views/admin/resource-categories/show.blade.php b/skolehjem/resources/views/admin/resource-categories/show.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/skolehjem/resources/views/admin/resource-categories/store.blade.php b/skolehjem/resources/views/admin/resource-categories/store.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/skolehjem/resources/views/admin/resource-categories/update.blade.php b/skolehjem/resources/views/admin/resource-categories/update.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index b371e91..317bd3b 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -39,3 +39,4 @@ Route::resource("washing-reservations", "WashingReservationController"); Route::resource("feedbacks", "FeedbackController"); Route::resource("external-links", "ExternalLinkController"); Route::resource("resource-extensions", "ResourceExtensionController"); +Route::resource("resource-categories", "ResourceCategoryController");