I think you don't know what kind of data you want. At the beginning you're defining $shoppingCart as collection, but later on $newShoppingCart is single model. Also in the else statement $shoppingCart is used in foreach, and that means it became single model (but previously was collection).
public function getCart()
{
// It should be under first if. Otherwise Auth::user()->id() will throw an error is user is not authenticated if
// you don't have some kind of guest user model defined.
$shoppingCart = ShoppingCart::where('user_id', Auth::user()->id())->get();
if(Auth::check())
{
if($shoppingCart->isEmpty())
{
// What is that? Shouldn't you add it to collection and pass that to blade?
$newShoppingCart = new ShoppingCart();
$newShoppingCart->user_id = Auth::user()->id;
// What is $cart variable?
$newShoppingCart->cart = json_encode($cart);
$newShoppingCart->save();
}else{
$user_id = Auth::user()->id;
$updateShoppingCart = ShoppingCart::where('user_id', $user_id)->get();
// Avoid using same name for variables that should contain different objects.
// Here $shoppingCart is supposed to be Eloquent model
// but above it's meant to be a collection.
foreach($updateShoppingCart as $shoppingCart)
{
// Again, what is $cart variable?
$shoppingCart->cart = json_encode($cart);
$shoppingCart->save();
}
}
}
// Here you are expecting that $shoppingCart is an collection or single model?
return view('public.shopping-cart', [
'shoppingCart' => $shoppingCart
]);
}
@extends('layouts.public')
@section('content')
<div class="content_wrapper">
<!-- Same here, are you want to handle model or collection? -->
{{ $shoppingCart }}
</div>
@stop
Describing context and what you want to achieve would be helpful.
// Edit:
Also, if you're serving your app by CLI command (php artisan serve) have you refreshed it?