Created
December 27, 2018 23:16
-
-
Save tripex/3c0a045be54b33e3b6ccffe122e5f6c8 to your computer and use it in GitHub Desktop.
Problems with session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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