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
Item Management
from the Laravel Examples section of the sidebar. 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. If you would
like to edit or dea tag you can click on the Action column. It is also possible to sort the
fields or to sein the fields.
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, description of the item, a dropdown to choose the category and a multiselect for the tags.
The App/Http/Controllers/ItemsController.php
handles data validation when adding a new item and the item creation
public function store(){
$attributes=request()->validate([
'name' => 'required|min:3|unique:items,name',
'category_id' =>'required|exists:categories,id',
'description' => 'required',
'picture' => 'required|mimes:jpg,jpeg,png,bmp,tiff |max:4096',
'tags' => 'required',
'tags.*' => 'exists:tags,id',
'status' =>'required|in:published,draft,archive',
'options' => 'required',
'date' => 'required'
]);
$path = request()->picture->store('pictures', 'public');
$attributes['picture'] = "$path";
$attributes['homepage'] = request()->homepage ? 1 : 0;
$attributes['options'] = request()->options ? request()->options : null;
$item = Item::create($attributes);
$item->tag()->sync(request()->get('tags'));
return redirect('items')->withStatus('Item successfully created.');
}
The policy which authorizes the user to access item management pages is implemented in
App\Policies\ItemPolicy.php
.