Пример #1
0
 /**
  * Saves specified hashtag $term to database and associates the hashtag with
  * the user logged in if applicable.
  *
  * @param  string $term hashtag term to save off
  */
 protected function saveHashtag($term)
 {
     // store most recently searched hashtag term in the global session
     \Session::put('searched_term', $term);
     // if a user is logged, then associate the user with the hashtag
     // otherwise, store hashtag term in global session until user logs in
     if (\Auth::check()) {
         // get the user id logged in
         $user_id = \Auth::id();
         // create a hashtag associated with the user if it does not exist
         \App\Hashtag::firstOrCreate(compact('term', 'user_id'));
     } else {
         if (!in_array($term, \Session::get('stored_terms', []))) {
             \Session::push('stored_terms', $term);
         }
     }
 }
Пример #2
0
 public function agregarACarrito(Request $request)
 {
     $producto = Producto::getProducto($request->input('id_producto'));
     $encontrado = false;
     $total = \Session::get('total_compra');
     foreach (\Session::get('carrito') as $producto_carrito) {
         if ($producto_carrito->id == $producto->id) {
             $encontrado = true;
             break;
         }
     }
     if (!$encontrado) {
         $total += $producto->precio;
         \Session::put('total_compra', $total);
         \Session::push('carrito', $producto);
         \Session::flash('poner_carrito', true);
     }
     return response()->json(['validado' => true]);
 }
 public function addToCart()
 {
     $aRequest = \Request::all();
     \Session::push("cart.items", $aRequest);
     // print_r(\Session::all());
 }