doucheng1944 2016-11-16 01:15
浏览 49
已采纳

如何在用户访问特定页面时更新页面匹配

I am using Laravel 5.2. How can I increment a hits field in articles table when a specific an article is visited by the user?

This is the code I came up with:

Article::where('id', 2)->increment('hits');

Where would be the best place to insert this code to?

  • 写回答

2条回答 默认 最新

  • dongzhuo7291 2016-11-16 02:15
    关注

    Make a middleware and then pass your requests through it. so whenever you request artical route it will be passed from that middleware and in middleware you can write logic for your increments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试