如何从Laravel的特定表中用户的上次登录后找到数据库条目?

问题描述:

我想找出一种方法,我可以计算从网站的管理员上次登录以来,有多少条目添加到数据库中的特定表中。如何从Laravel的特定表中用户的上次登录后找到数据库条目?

当我创建管理面板时,我需要知道自管理面板上次登录管理员以来,数据库表中有多少订阅请求到达。

我只想显示收到的请求数量? 我正在使用Laravel和MySQL的数据库。

创建一个表来存储静:

id | count | readed 

添加监听到你的订阅请求模式,对每一个Creation Event(添加它在供应商)触发:在

SubscriptionRequest::created(function ($data) { 
     //look for last statics record 
    $last_static_unread = Statics::where('readed',0)->first(); 
    //if there aren't any record is our first request since last login 
     if(is_null($last_static_unread)){ 
     $last_static_unread = new Statics(); 
     $last_static_unread->count = 1; 
     $last_static_unread->readed = 0; 
     $last_static_unread->save(); 
     }else{ 
     $last_static_unread += 1; 
     $last_static_unread->update(); 
     } 
}); 

然后你管理面板得到它并更新它,例如在控制器中为主要静力学视图提供服务:

public function getTotalRequestSinceLastVisit(){ 
    $last_statics = Statics::where('readed',0)->first() 
    $total_requests = 0; 
    if(!is_null($last_statics)){ 
     $total_requests = $last_statics->count; 
     $last_statics->readed = 1; 
     $last_statics->update(); 
    } 
    return $total_requests; 
}