@sergiu17 yes I did. And I'm confused why this is not uploading the image.
Nov 26, 2020
13
Level 9
Error Call to a member function store() on null
In my project I'm using livewire functionality for updating the value. But in this case if I upload an image it send me an error.
Error
Call to a member function store() on null
Can anyone please tell me how can i solve this. I read the documentation and follow as he mentioned but i did not understand whats wrong with with this function.
This is livewire component method
use WithFileUploads;
public $admin_panel_value;
public $admin_alt_text;
public $admin_logo;
public function adminLogoDataSave()
{
$this->validate([
'admin_alt_text' => 'required|string|max:50',
// 'admin_photo' => 'image|mimes:png,jpg|max:102400', // 1MB Max
]);
$adminLogo = Logo::where('options','admin_panel_logo')->findOrFail(1);
$pic = $this->admin_logo->store('photos');
// dd($pic);
// $adminLogo->update([
// 'alt_text' => $this->admin_alt_text,
// ]);
}
and this livewire blade component
<form wire:submit.prevent="adminLogoDataSave" enctype="multipart/form-data">
<div class="card-body">
<div class="form-group">
<label for="logotext">Logo Text</label>
<input
type="text"
name="admin_alt_text"
wire:model.defer="admin_alt_text"
class="form-control"
id="logotext" aria-describedby="logotext"
>
@error('admin_alt_text')<span class="text-danger">{{ $message }}</span> @enderror
</div>
<div class="form-group">
<input type="text" value="{{ $admin_panel_value->options }}">
</div>
<div class="form-group">
<label for="admin_logo">Select Logo</label>
<input
type="file"
name="admin_logo"
wire:model="admin_logo"
class="form-control-file"
id="admin_logo">
<small id="logo_path" class="form-text text-muted">JPEG, PNG only</small>
@error('admin_logo') <span class="error">{{ $message }}</span> @enderror
</div>
</div>
<div class="card-footer border-top white-bg text-right">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
Level 122
The file input cannot be cleared - a feature common to all browsers.
I have a workaround described here;
1 like
Please or to participate in this conversation.