Answer the question
In order to leave comments, you need to log in
When adding a product to the cart, I add all the data to the session. What if I add another item?
When adding a product to the cart, I add all the data to the session. What if I add another item? I can’t figure out how to process, I have something like this output in the view:
@if(Session::has('user_order_product'))
{{ Session::get('user_order_product')->title }}<br>
{{ Session::get('user_order_color') }}<br>
{{ Session::get('user_order_size') }}<br>
{{ Session::get('user_order_count') }}<br>
@endif
Answer the question
In order to leave comments, you need to log in
You somehow incorrectly store data in the session, why save each value separately when you can save one product as an array.
$item = ['id' => 1, 'title' => 'someTitle', 'other_field' => 'otherFieldlValue'];
$_SESSION['cart_items'][] = $item;
//либо так
$_SESSION['cart_items'][$item['id']] = $item;
//второй способ предотвращает повторное добавление одного и того же товара
Привет! Вот серия уроков про Интернет-магазин на Laravel 5. Может возьмешь что-нибудь полезное :) Там через JS корзина на сколько я знаю.
otdel-devsite.ru/laravel-5-%D0%BF%D0%B8%D1%88%D0%B...
Не мучайтесь и попробуйте использовать gloudemans/shoppingcart
https://github.com/Crinsane/LaravelShoppingcart
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question