如何在listen方法中计算受影响的行数-Laravel

时间:2019-03-19 14:17:02

标签: php laravel eloquent

我使用laravel的listen方法为每个查询创建日志。我得到所有这样的sql查询:

\DB::listen(function($q) {
    $query = $q->sql;
    //Save in logn
});

我想获取查询是更新还是删除时修改的列数。

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

in your controller

(1) using Eloquent:

 use App\Project;

 public function totalprojects()
        {
            $total_projects = Project::count();
            return view('summarys.summary')->with(['total'=>$total_projects]);
        }

(2) using Query Builder:

use DB;
  public function totalprojects()
            {
                $total_projects = DB::table('projects')->count();
                return view('summarys.summary')->with(['total'=>$total_projects]);
            }

in your blade :

<p>{{ $total }}</p>