Closed Romik90 closed 5 years ago
What does your controller code on /shop URI do? What does it do on other pages?
@fulopattila122 it does nothing special `class ProductController extends Controller { /* @var ProductSearcher / private $productSearcher;
public function __construct(ProductSearcher $productSearcher)
{
$this->productSearcher = $productSearcher;
}
public function index(ProductIndexRequest $request, string $taxonomyName = null, Taxon $taxon = null)
{
$properties = PropertyProxy::get();
if ($taxon) {
$this->productSearcher->withinTaxon($taxon);
}
return view('pages.categories', [
'products' => $this->productSearcher->popular()->paginate(30),
'taxon' => $taxon,
'properties' => $properties,
'filters' => $request->filters($properties)
]);
}`
If I dd(\Cart::getItems()) inside index method, it shows correct cart items, but if I do the same in the template, it shows me everythins that exists in cart_items table
Can you show the code you're using in the template?
{{ dd(Cart::model()) }} at the very beginning
Never use the Cart::model()
.
Here's a good example how to use the Cart facade in views: https://github.com/vanilophp/demo/blob/0.5/resources/views/cart/show.blade.php
Did that solve the problem?
No. I actually use cart facade as in your demo. So I did {{ dd(Cart::getItems()) }} and result is the same, I see cart items from different carts which belongs to defferent users Collection {#714 ▼
0 => CartItem {#720 ▶}
1 => CartItem {#719 ▶}
2 => CartItem {#718 ▶}
3 => CartItem {#717 ▶}
] } In database
config/vanilo.php 'cart' => [ 'extra_product_attributes' => ['weight', 'size', 'partner_id'], 'preserve_for_user' => true, ]
And again, if I output cart items on main page, I see correct cart with only mine items Collection {#646 ▼
}
Does that route have the web middleware? Looks like you have no session.
I found out that in the web middleware group \Illuminate\Session\Middleware\AuthenticateSession::class was commented. After uncommenting everything works correct. Thank you so much, you saved my life!
If I open /shop uri or product page, Cart::getItems() return all items from database that belongs to different carts and users. On other pages everything works fine.
dd(Cart::model()) on /shop uri show this
relations: array:2 [▼
]
on any other page:
relations: []
And ideas why?