Item Management

Item management is the most advanced example included in the Pro theme, because every item has a picture, belongs to a category and has multiple tags. To access this example click the “Laravel Examples/Item Management” link in the left sidebar or add /items to the URL. Here you can manage the items. A list of items will appear once you start adding them (to access the add page click “Add item”). On the add page, besides the Name and Description fields (which are present in most of the CRUD examples) you can see a category dropdown, which contains the categories you added, a file input and a tag multi select. If you did not add any categories or tags, please go to the corresponding sections (category management, tag management) and add some.

The code for saving a new item is a bit different than before (see snippet bellow):

public function add()
    {
            $this->validate();

            // dd($this->tags_id);

            $item = Item::create([
                'name' => $this->name,
                'category_id' => $this->category_id,
                'excerpt' => $this->excerpt,
                'description' => $this->description,
                'date' => $this->date,
                'status' => $this->status,
                'show_on_homepage' => $this->showOnHomepage,
                'options' => $this->options
            ]);

            sort($this->tag_id);
            $item->tags()->sync($this->tag_id, false);

            $this->showSavedAlert = true;

            $this->upload && $item->update([
                'picture' => $this->upload->store('/', 'items'),
            ]);
        }
    }
Similar to all the examples included in the theme, this one also has validation rules in place.