app/Providers/AppServiceProvider.php
/**
     * Bootstrap any application services.
     *
     * @return void
     */
Bootstrap any application services.
@return void
Bootstrap any application services . @return void
public function boot()
    {
        view()->composer('banxe.layout.header',function($view){
            $loaisp = ProductType::all();
            $view -> with('loaisp', $loaisp);
        });
        View::composer(['banxe.layout.header','banxe.dathang'],function($view){
            if(Session('cart')){
                $oldCart=Session::get('cart'); 
                $cart=new Cart($oldCart);
                $view->with(['cart'=>Session::get('cart'),'productCarts'=>$cart->items,'totalPrice'=>$cart->totalPrice,'totalQty'=>$cart->totalQty]);
            }
        });
    }
public function boot ( ) { view ( ) -> composer ( 'banxe.layout.header' , function ( $ view ) { $ loaisp = ProductType :: all ( ) ; $ view -> with ( 'loaisp' , $ loaisp ) ; } ) ; View :: composer ( [ 'banxe.layout.header' , 'banxe.dathang' ] , function ( $ view ) { if ( Session ( 'cart' ) ) { $ oldCart = Session :: get ( 'cart' ) ; $ cart = new Cart ( $ oldCart ) ; $ view -> with ( [ 'cart' => Session :: get ( 'cart' ) , 'productCarts' => $ cart -> items , 'totalPrice' => $ cart -> totalPrice , 'totalQty' => $ cart -> totalQty ] ) ; } } ) ; }
Bootstrap any application services.
Bootstrap any application services .
//chia sẻ biến Session('cart'),.. cho các view header.blade.php và checkout.php //session cart được tạo trong method addToCart của PageController