PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 16, 2022

[FIXED] How to Count Value According to date in Laravel?

 November 16, 2022     eloquent, laravel, laravel-6, laravel-6.2, mysql     No comments   

Issue

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();


Answered By - Sehdev
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing