public function addItem()
{
$this->validate([
'photo' => 'image|max:10000',
]);
$item = Item::create([
'name' => $this->itemName,
'amount' => $this->itemAmount,
'shelf_sec' => $this->itemLetter,
'shelf_num' => $this->itemNumber,
'img' => $this->hasFile('photo') ? $this->photo->store('photos') : 'no-photo-available.png'
]);
$this->items = Item::all();
}
You may determine if a file is present on the request using the
hasFilemethod.
Docs: https://laravel.com/docs/8.x/requests#retrieving-uploaded-files