I have the following functionality that was working correctly but suddenly it stopped working and I can't detect what the problem is.
It doesn't have a form and I don't use the request either. That's why I run it from Livewire:
Blade
<div class="form-group">
<label for="portada">Portada <small class="text-danger">*</small></label>
<input wire:model="portada" type="file" class="form-control-file" name="portada" id="portada">
</div>
Component
//Guardamos la foto de portada
$pathFoto = $this->foto->store('imagenPortada');
// Creamos primero el usuario
User::create([
'tipo_usuario' => $this->tipo_de_usuario,
'name' => $this->nombre_usuario,
'apellido' => $this->apellido_usuario,
'documento' => $this->documento_usuario,
'telefono' => $this->telefono_usuario,
'telegram' => $this->telegram,
'email' => $this->email,
'password' => Hash::make($this->password),
'permiso' => $this->permiso,
'perfil' => asset($pathFoto)
]);
The error:
Call to a member function store() on null {"exception":"[object] (Error(code: 0): Call to a member function store() on null
Solution: Thanks @L.Flor, do it as follows:
public $foto = null;
if(!empty($this->foto)){
$pathFoto = $this->foto->store('imagenPortada');
}else{
$pathFoto = null;
}
If photo is not a required parameter, then you just need to check that it's not null first.