forked from eatvio/eatvio-infra
live charts update added
This commit is contained in:
44
app/Http/Livewire/Profile/WeightChart.php
Normal file
44
app/Http/Livewire/Profile/WeightChart.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user