Démo Livewire 3
mdfdfdf
Le code de la page Statistiques
<?php
namespace App\Livewire;
use Livewire\Component;
class Statistiques extends Component
{
public float $prix;
public int $nombre;
public int $caMoisCourant;
public int $caMoisPrecedent = 22124;
public function mount()
{
$this->prix = 15.66;
$this->nombre = 175;
$this->changeCa();
}
public function changeCa()
{
if (!isset($this->nombre)) {
// Correction si le nombre est effacé par l'utilisateur
$this->nombre = 0;
}
if ($this->nombre > 100000) {
// Correction si le nombre trop grand
$this->nombre = 100000;
}
$this->caMoisCourant = round($this->prix * $this->nombre);
}
public function render()
{
return view('livewire.statistiques');
}
}
Le code blade & livewire (HTML) :
<div>
<x-header title="Statistiques" separator/>
<div class="p-4 bg-base-100 grid grid-cols-1 lg:grid-cols-8">
<x-stat title="CA HT" description="Mois précédent" value="{{ $caMoisPrecedent }} €" icon="o-arrow-trending-up"/>
<x-stat title="Pièces" description="Mois courant" value="{{ $nombre }}" icon="m-square-2-stack"/>
<x-stat title="Prix" description="Mois courant" value="{{ $prix }} €" icon="o-currency-euro"/>
@if($caMoisCourant > $caMoisPrecedent )
<x-stat title="CA HT" description="Mois courant" value="{{ $caMoisCourant }} €"
icon="o-arrow-trending-up" class="text-green-500"/>
@else
<x-stat title="CA HT" description="Mois courant" value="{{ $caMoisCourant }} €"
icon="o-arrow-trending-down" class="text-orange-500" color="text-orange-500"/>
@endif
</div>
@if($nombre == 1413 )
<div class="p-4 bg-base-100 grid grid-cols-1 lg:grid-cols-2">
<x-alert icon="o-exclamation-triangle" class="alert-success">
<strong>Bravo !</strong> Le nombre pivot est bien celui-ci !
</x-alert>
</div>
@endif
<div class="p-4 bg-base-100">
<h2>Saisissez le nombre de pièces pivot à vendre pour faire un meilleur CA que le mois précédent.</h2>
</div>
<div class="p-4 bg-base-100 grid grid-cols-1 lg:grid-cols-8">
<x-input label="Nombre" wire:model="nombre" wire:keydown="changeCa()"
hint="Maximum: 100 000"/>
</div>
</div>
Et c'est tout !
Démo Livewire 3
mdfdfdf