[英]which to use Cookie or Session? laravel 5.7 - to store data for 5 minutes
guys I'm trying to have 4 steps payment in my application in laravel 5.7伙计们,我正在尝试在 laravel 5.7 的应用程序中进行 4 步付款
then I wanna store these data in somewhere 4 steps until the payment have been completed and after that I want to store them on database然后我想将这些数据存储在 4 个步骤中,直到付款完成,然后我想将它们存储在数据库中
these 4 steps contains:这 4 个步骤包含:
now please prefer your ways现在请更喜欢你的方式
which to use?使用哪个? cookie or session or something else ?
cookie或会话或其他什么?
I would use session but I want those data destroyed after 5 minutes and if I choose session lifetime to 5 minutes all of session data will destroy like my login session and I just want destroy the session that I created.我会使用会话,但我希望这些数据在 5 分钟后销毁,如果我选择会话生存期为 5 分钟,所有会话数据都将像我的登录会话一样销毁,我只想销毁我创建的会话。
The data you want to store temporarily is a cart quote data in terms of e-commerce.您要临时存储的数据是电子商务方面的购物车报价数据。 You can store this data in the database, with a timestamp column
expires_at
having value of current time + 5 minutes
.您可以将此数据存储在数据库中,时间戳列
expires_at
值为current time + 5 minutes
。
Then in your model global scope, which will always filter queries and only get non-expired data :然后在您的模型全局范围内,它将始终过滤查询并仅获取未过期的数据:
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::addGlobalScope('expires_at', function (Builder $builder) {
$builder->where('expires_at', '<=', Carbon::now());
});
}
Sessions provide a way to store information about the user across multiple requests, you should check https://laravel.com/docs/5.7/session for me is the best option.In the session driver configuration option you can defines where session data will be stored for each request, for example cookie
, were sessions are stored in secure, encrypted cookies.会话提供了一种跨多个请求存储用户信息的方法,您应该检查https://laravel.com/docs/5.7/session对我来说是最好的选择。在会话驱动程序配置选项中,您可以定义会话数据的位置为每个请求存储,例如
cookie
,如果会话存储在安全的加密 cookie 中。 Then for your problem about destroy de data you can use the forget method will remove a piece of data from the session.然后,对于有关销毁数据的问题,您可以使用忘记方法将从会话中删除一段数据。 If you would like to remove all data from the session, you may use the flush method.
如果您想从会话中删除所有数据,您可以使用flush 方法。
// Forget a single key...
$request->session()->forget('key');
//or
$request->session()->flush();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.