Search code examples
mysqllaraveleloquentlaravel-6laravel-6.2

How to Count Value According to date in Laravel?


I have multiple fields store in my database table, and there are followup field in my database and there are multiple dates store in this field. Now i want count data according to current date. But i am unable to do it.

I am getting same data multiple times, but i want in this format (Suppose there are 5 date store according to today date and they should be count 5, so that i can get the today followup clients )

Please let me know how i can do it.

Here are my controller code..

public function index()
 {
$lead=Lead::orderBy('created_at', 'desc')->get()
return view('admin.lead.index',compact('lead'));
 }

and here are my view file..

<div class="panel-heading">
@php
$mytime = Carbon\Carbon::now();
$checkdate=$mytime->toDateTimeString();
@endphp
<div class="panel-title">Today Follow Up's: 
    @foreach($lead as $lws)
        <span class="label label-warning">
            {{($lws->followup=$checkdate)}}
        </span>
    @endforeach
</div>
</div>

Solution

  • You can use below code to get only today's follow ups:

    $lead=Lead::whereDate('followup', date('Y-m-d'))->get();
    

    or to count the records:

    $lead=Lead::whereDate('followup', date('Y-m-d'))->get()->count();