Items 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 /laravel-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 + New Item button or add in the url /laravel-new-item
.
If you would like to edit or delete a tag you can click on the Action column. It is also possible to sort the fields
or to search in 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, excerpt, description of the item, a dropdown to choose the category and a multiselect for the tags.
The `App\Http\Livewire\LaravelExample\NewItem`
handles data validation when adding a new item and the item creation(see snippet below):
public function addItem() {
$this->validate();
$item = Item::create([
'name' => $this->name,
'excerpt' => $this->excerpt,
'description' => $this->description,
'category_id' => $this->category_id,
'status' => $this->status,
'show_on_homepage' => $this->showOnHomepage,
'options' => $this->options
]);
$this->date && $item->update([
'date' => Carbon::parse($this->date)->format('Y-m-d')
]);
$this->photo && $item->update([
'picture' => $this->photo->store('/', 'items')
]);
$item->tags()->sync($this->tags_id, false);
}
For deleting an item is necessary to remove the association between item and tags. The `App\Http\Livewire\LaravelExample\ItemsManagement`
handles the deletion of an item:
public function delete($id) {
$item = Item::find($id);
$item->tags()->detach();
$item->delete();
$this->showSuccesNotification = true;
}