Summer Sale! All accounts are 50% off this week.

Araw's avatar
Level 1

How to Display Session values in HTML

I Try This

	<li><a href="{{route('cartProducts')}}"><i class="fa fa-shopping-cart"></i> Cart<span style="color:green;font-weigth:400px;">{{ Session::get('cart')[0]}}</span></a></li>

And I want to get the Value of totalquantity from the below session

 $cart = Session::get('cart');

0 likes
4 replies
automica's avatar

@araw your $cart variable will contain that as part of its object.

if you dd($cart), you'll be able to see what the key name is and access it accordingly.

This will be something along the lines of

$cart['totalquantity']

BTW if you need the $cart variable in your blade, then its best to pass it in from your controller rather than call Session::get() directly in your blade.

Araw's avatar
Level 1
	<li><a href="{{route('cartProducts')}}"><i class="fa fa-shopping-cart"></i> Cart<span style="color:green;font-weigth:400px;">{{!! Session::get('cart') !!}}</span></a></li>

Give Error to me

Object of class App\Cart could not be converted to string (View: D:\EcommerceProjectMA\EcomMA\resources\views\layouts\header.blade.php)

automica's avatar
automica
Best Answer
Level 55

@araw use

session('cart');

if you are in your blade.

as we're trying to find where the totalquantity key is set, can you insert the following bit of code in the top of your blade, and copy the output to here.

            <?php 
                $cart = session('cart');
                dd($cart);
            ?>

this should allow us to see whats stored in session for 'cart'

Please or to participate in this conversation.