forked from eatvio/eatvio-infra
38 lines
768 B
PHP
38 lines
768 B
PHP
<?php
|
|
|
|
namespace App\Http\Livewire\User;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
use App\Models\WeightMeasure;
|
|
|
|
class AddWeight extends ModalComponent
|
|
{
|
|
public User $user;
|
|
public $weight = 0;
|
|
|
|
public function mount()
|
|
{
|
|
$this->user = Auth::user();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.user.add-weight');
|
|
}
|
|
public function add()
|
|
{
|
|
$newMeasure = WeightMeasure::create([
|
|
'user_id' => $this->user->id,
|
|
'weight' => $this->weight,
|
|
]);
|
|
$newMeasure->save();
|
|
$this->reset(['weight']);
|
|
|
|
$this->emitTo('profile.weight-chart', 'weight-chart-updated');
|
|
$this->closeModal();
|
|
}
|
|
|
|
}
|