Item Management
All three types of users have access to a tags management table page.
Item Management is the most advanced example included in the PRO theme because every item has a picture, has a category and has multiple tags.
The item management can be accessed by clicking Items Management
from the
Laravel Examples section of the sidebar or adding /items-management
in the url. The authenticated user as an Admin or Creator is able to add, edit and delete items.
For adding a new item you can press the Add Item button or add in the url /new
.
If you would like to edit or delete a tag you can click on icons in the Action column. It is also possible to sort the fields
or chnage pagination.
On the page for adding a new item you will find a form which allows you to add an image of the item, to fill the name, excerpt, description of the item, a dropdown to choose the category and a multiselect for the tags.
The `App\Http\Controllers\ItemController.php`
handles data validation when adding a new item and the item creation(see snippet below):
public function store(Request $request)
{
$attributes = request()->validate([
'name' => ['required', 'unique:items'],
'excerpt' => ['max:100'],
'description' => ['max:255'],
'choices-category' => ['required'],
'tags' => ['required'],
]);
$item = Item::create([
'name' => $request->get('name'),
'excerpt' => $request->get('excerpt'),
'description' => $request->get('description'),
'category_id' => $request->get('choices-category'),
'date' => $request->get('date'),
'status' => $request->get('status'),
'show_on_homepage' => $request->get('show_on_homepage'),
'options' => $request->get('option')
]);
....
}
For deleting an item is necessary to remove the association between item and tags. The same controller handles the deletion of an item:
public function delete($id) {
$item = Item::find($id);
$item->tags()->detach();
$item->delete();
$this->showSuccesNotification = true;
}