I’m creating a shop on Laravel 9 and I would like to add a shopping basket with the number of products I have added on my ‘paniers’ SQL table.
I wrote this on my controller :
public function AffichageBoutique()
{
$boutiques = Boutique::all();
$nbr = Panier::where('iduser', session('iduser'))->get()->count();
return view('boutique.Boutique')->with('boutiques', $boutiques)->with('paniers', $nbr);
}
$nbr is the number of my products I have on my basket, for example -> 4.
I would like to display this number on my page like this, it’s an animated basket =>
<div class="icon-wrapper">
<figure>
<img src="/img/icons/bell_icon.svg" alt="" class="bell-icon">
<figcaption>
<p>{{ $nbr }}</p>
</figcaption>
</figure>
</div>
But I have this error : Undefined variable $nbr.
What’s the problem ??
Thank you !
>Solution :
return view('boutique.Boutique')->with('boutiques', $boutiques)->with('paniers', $nbr);
in your return you are passing the $nbr variable and renaming it as 'paniers', either you change the name to 'nbr' (->with('nbr', $nbr)) or in your html you call for $paniers
You can find more in Laravel official documentation