本文整理汇总了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());
}