Livewire Image Upload Problem
I have follow the documentation but the image doesn't seem to be placed in the file directory, it is just being placed in the livewire-tmp directory.
<div class="custom-file">
<input type="file" class="custom-file-input" id="custom-file-input" wire:model.defer="image">
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
public function addItem()
{
try
{
$item = array(
'name' => $this->itemName,
'amount' => $this->itemAmount,
'letter' => $this->itemLetter,
'number' => $this->itemNumber,
'img' => $this->image,
);
$this->validate([
'photo' => 'image|max:10000',
]);
$this->photo->store('images');
}
catch (\Throwable $th)
{
$this->message = true;
}
}
after your code runs I would expect to see the image still in the temp folder but also in the images folder on the default disk
Ah it is crazy. I have no idea why, I have copied it line for line from the documents.
If anyone can help please.
gh repo clone JoshuaHeathcote1987/register
Inventory - addItem
New Code to show it is fully copied
// Variables
public $photo;
public function addItem()
{
$this->validate([
'photo' => 'image|max:10000',
]);
$this->photo->store('photos');
// try
// {
// $item = array(
// 'name' => $this->itemName,
// 'amount' => $this->itemAmount,
// 'letter' => $this->itemLetter,
// 'number' => $this->itemNumber,
// 'img' => $this->photo,
// );
// $this->validate([
// 'photo' => 'image|max:10000',
// ]);
// $this->photo->store('photos');
// }
// catch (\Throwable $th)
// {
// $this->message = true;
// }
}
<form autocomplete="off" wire:submit.prevent="addItem">
<div class="modal fade" id="addItemModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" wire:ignore.self>
<div class="modal-dialog modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<div class="col-lg-4">
<label for="" class="col-sm-2 col-form-label text-right">Name</label>
</div>
<div class="col-lg-8">
<input type="text" class="form-control" wire:model.defer="itemName">
</div>
</div>
<div class="form-group row">
<div class="col-lg-4">
<label for="" class="col-sm-2 col-form-label text-right">Amount</label>
</div>
<div class="col-lg-8">
<input type="text" class="form-control" wire:model.defer="itemAmount">
</div>
</div>
<div class="form-group row">
<div class="col-lg-4">
<label for="" class="col-sm-2 col-form-label text-right">Section</label>
</div>
<div class="col-lg-4">
<select class="form-control" id="exampleFormControlSelect2" wire:model.defer="itemLetter">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</div>
<div class="col-lg-4">
<select class="form-control" id="exampleFormControlSelect2" wire:model.defer="itemNumber">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-lg-4">
<label for="" class="col-sm-2 col-form-label text-right">Image</label>
</div>
<div class="col-lg-8">
<div class="custom-file">
{{$photo}}
<input type="file" class="custom-file-input" id="custom-file-input" wire:model="photo">
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" data-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>
</form>
dd in the function to make sure its called
look in the photos folder of the default disk for a randomly named file
Wasn't working, dd it. Just like magic, starts working. Thanks Snape.
Please or to participate in this conversation.