本文整理匯總了PHP中App\Http\Controllers\Session::push方法的典型用法代碼示例。如果您正苦於以下問題:PHP Session::push方法的具體用法?PHP Session::push怎麽用?PHP Session::push使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類App\Http\Controllers\Session
的用法示例。
在下文中一共展示了Session::push方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: saveHashtag
/**
* 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: agregarACarrito
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]);
}
示例3: addToCart
public function addToCart()
{
$aRequest = \Request::all();
\Session::push("cart.items", $aRequest);
// print_r(\Session::all());
}