reclamar premio

This commit is contained in:
Felipe
2024-03-06 12:03:57 -05:00
parent df7522c2a9
commit 3d1eac3801
6 changed files with 80 additions and 45 deletions
+33
View File
@@ -3,13 +3,18 @@
namespace App\Http\Livewire;
use App\Models\Notificacion;
use App\Models\Saldo;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Jantinnerezo\LivewireAlert\LivewireAlert;
class Bell extends Component
{
use LivewireAlert;
public $numNoti = 0;
public $menuNotificaciones = false;
public $reclamandoPremio = false;
public function render()
{
@@ -35,4 +40,32 @@ class Bell extends Component
$notificacion->update(['estado' => false]);
}
}
public function reclamarPremio($id)
{
if ($this->reclamandoPremio) {
return;
}
$this->reclamandoPremio = true;
$notificacion = Notificacion::find($id);
$consulta_saldo = Saldo::where('usuario_id', Auth::user()->id)->first();
if ($consulta_saldo) {
$consulta_saldo->update([
'valor' => $consulta_saldo->valor + $notificacion->premio
]);
if ($notificacion) {
$notificacion->update(['estado' => false]);
}
}
$this->reclamandoPremio = false;
$this->alert('success', 'Haz reclamado el premio correctamente', [
'position' => 'top'
]);
}
}