如何让用户等待Laravel [英] How to make a user wait with Laravel

查看:37
本文介绍了如何让用户等待Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.3,并且已经构建了一个我们可以认为类似于电子商务应用程序的应用程序.我本质上是希望允许用户在应用程序内(而不是通过电子邮件)对他们的订单进行评论,但要让他们在购买后等待X天.几乎像eBay一样...

I'm using Laravel 5.3 and I've built an application of which we can think of as sort of like an e-commerce app. I essentially want to allow the user to leave a review for their order, inside the application (not by email), but have them wait X amount of days after their purchase. Like eBay almost...

但是在用户执行类似操作之前创建等待时间的通常惯例是什么?我一直在考虑是否应该设置cron作业以在X天后向用户发送请求,或者应该以某种方式将其记录在数据库中,尽管我认为在有很多用户的情况下这会占用大量数据库.

But what is the usual convention for creating a waiting period before a user can perform an action like this? I've been thinking whether I should set up cron jobs to send the user a request after X amount of days or perhaps by logging this in the database somehow, though I imagine that to be database heavy when having lots of users.

任何想法都将不胜感激.

Any thoughts would be appreciated.

更新:其想法是强制用户等待时间.他们要等到等待期 后才能发表评论.

Update: The idea is to force a wait time upon the user. They can't leave a review until after the waiting period.

推荐答案

据我了解您的用例,您需要一种持久的存储方法来记住自购买该商品以来已经过了多少天.通常,有四种持久存储方法:

As I understand your use case, you need a persistent storage method to remember how many days have passed since the purchase of the item. There are, in general, 4 methods of persistent storage:

1.Cookies :

  • 存储:客户端(但是安全,因为Laravel加密并签名了所有cookie)
  • 特定:对于用户计算机和域而言是唯一的
  • 持续时间:可以永久持续,除非用户明确删除cookie
  • 常见用例:已保存的首选项

2.会话

  • 存储:服务器端(取决于驱动程序)
  • 特定:特定于用户(但取决于驱动程序)
  • 持续时间:通常会在几个小时后到期,但可以延长
  • 常见用例:从一个请求到另一个请求的持久层(例如购物车,动作触发后的弹出通知)

3.缓存

  • 存储:服务器端
  • 特定的:通常特定于应用程序(但也可以是特定于用户的)
  • 持续时间:通常一个小时到几天
  • 常见用例:特定于应用程序的存储用例(例如,总点击数,最受欢迎的页面,数据库查询缓存,视图缓存)

4.数据库

  • 存储:服务器端
  • 特定的:可以特定于用户或应用
  • 持续时间:直到删除为止
  • 常见用例:长期数据持久层(例如,用户详细信息)

现在,如果要在购买几天后向用户发送自动提醒,则持久层必须在服务器端.这样就排除了cookie,而且缓存也不是一个好方法(因为缓存最好用于应用程序特定的数据,而不是用户特定的数据).但是,如果您要寻找由用户触发的评论,建议您使用Cookie.

Now, if you want to send an automated reminder to the users after a couple of days of the purchase, the persistence layer has to be server side. That rules out cookies and also caching would not be a good method (since caching is best used for app specific data, not user specific data). But if you're looking for the review to be triggered by a user, I would suggest using cookies.

不用说,自动提醒需要由cron作业触发.

Needless to say, automated reminders need to be triggered by cron jobs.

摘要:

  • 如果要自动提醒:使用数据库+ cron作业
  • 如果您不希望自动提醒,请使用Cookie

这篇关于如何让用户等待Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆