Added resource category migration and empty blade files

This commit is contained in:
Vedde 2020-07-01 09:08:33 +02:00
parent f0132bee2c
commit 54a0fd0997
10 changed files with 64 additions and 9 deletions

View File

@ -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");
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateResourceCategories extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('resource_categories', function (Blueprint $table) {
$table->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');
}
}

View File

@ -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");