Category management


Out of the box you will have an example of category management (for the cases in which you are developing a blog or a shop). To access this example, click the “Laravel Examples/Category Management” link in the left sidebar or add /laravel-examples/category-management to the URL. You can add and edit categories here, but you can only delete them if they are not attached to any items.

The store used for category form is found in app/Http/Controllers/CategoryController.

You can find the functions for category form in resources/views/laravel-examples/category folder.

Category Controller

public function store(Request $request)
{
    $request->validate([

        'name' => 'required|min:3|max:255',
        'description' => 'required|min:3|max:255',
    ], [
        'name.required' => 'Name is required',
        'description.required' => 'Description is required',
    ]);

    $category = Category::create([
        'name' => $request->name,
        'description' => $request->description,
    ]);

    return redirect(route('category-management'))->with('success', 'New category added successfully.');
}