forked from eatvio/eatvio-infra
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire\Profile;
|
|
|
|
use Livewire\Component;
|
|
use App\Models\User;
|
|
use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
|
|
|
class WeightChart extends Component
|
|
{
|
|
public User $user;
|
|
|
|
protected $listeners = ['weight-chart-updated' => '$refresh'];
|
|
|
|
public function render()
|
|
{
|
|
$areaChartModel =
|
|
(new AreaChartModel())
|
|
->setSmoothCurve()
|
|
->setColors(['#b7d7e8']);
|
|
|
|
$lastFourWeightMisures = $this->user
|
|
->weight_measures()
|
|
->orderBy('created_at', 'desc')
|
|
->limit(4)
|
|
->get()
|
|
->sortBy('id');
|
|
|
|
$lastFourWeightMisures->each(
|
|
function ($item, $key) use ($areaChartModel) {
|
|
$createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y');
|
|
$areaChartModel->addPoint($createdAt, $item['weight']);
|
|
}
|
|
);
|
|
|
|
return view(
|
|
'livewire.profile.weight-chart',
|
|
[
|
|
'user' => $this->user,
|
|
'areaChartModel' => $areaChartModel,
|
|
]
|
|
);
|
|
}
|
|
}
|