Skip to content

Instantly share code, notes, and snippets.

@tripex
Created December 27, 2018 23:16
Show Gist options
  • Save tripex/3c0a045be54b33e3b6ccffe122e5f6c8 to your computer and use it in GitHub Desktop.
Save tripex/3c0a045be54b33e3b6ccffe122e5f6c8 to your computer and use it in GitHub Desktop.
Problems with session
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class CartController extends Controller {
protected $cart;
public function __construct() {
$this->cart = session('cart');
dump( session( 'cart' ) );
if ( ! $this->cart['products'] ) {
echo "lalala";
$this->cart = array( 'products' => array(), 'total' => 0.00 );
session( [ 'cart' => $this->cart ] );
}
}
public function add_to_cart( Request $request ) {
dump( $this->cart );
$product = $request['product'];
$attributes = $request['attributes'];
if ( array_has( $product, [ 'id', 'name', 'price' ] ) ) {
if ( null !== $attributes ) {
}
array_push( $this->cart['products'], $product );
session()->put( 'cart', $this->cart );
dump( session()->get( 'cart' ) );
return $this->cart;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment