Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

username1's avatar

How to get all data in by date in laravel?

good day I want to get all data by date, when diplaying the same date will not come out, only data in that date,

in my controller .. $job_order = JobOrder::whereNotNull(['er_total','mf_total','calib_total','overall_total','created_at']) ->when($this->start_date && $this->end_date, function ($query) { $query->where('created_at', '>=', $this->start_date); $query->where('created_at','<=', Carbon::parse($this->end_date)->addHour(23)->addMinute(59)->addSecond(59)); })->get();

0 likes
7 replies
username1's avatar
      $job_order = JobOrder::whereNotNull(['er_total','mf_total','calib_total','overall_total','created_at'])        
        ->when($this->start_date && $this->end_date, function ($query) {
            $query->where('created_at', '>=', $this->start_date);
            $query->where('created_at','<=', Carbon::parse($this->end_date)->addHour(23)->addMinute(59)- 
  >addSecond(59));
        })->get();
username1's avatar

@frankielee what I want to get is the data from database per created_at, and when displaying that data, the same date will not display, I want to get all the data per date and total all those data.

frankielee's avatar

@username1 Apologize, I missed that.

Try using groupBy, probably something like this.

>when($this->start_date && $this->end_date, function ($query) {
			$endDate = Carbon::parse($this->end_date)->addHour(23)->addMinute(59)- 
  >addSecond(59);
		$query->whereBetween('created_at',[$this->start_date,$endDate])->orderBy('created_at', 'asc')->groupByRaw("date(created_at)");
  })

username1's avatar

@frankielee yeah I already group the data but the problem now is how to display data in blade base in its date, if there are multiple data in current date, I hope you get my point,

this is my controller...

             $job_order = JobOrder::whereNotNull(['er_total','mf_total','calib_total','overall_total','created_at'])
            ->when($this->start_date && $this->end_date, function ($query) {
                $query->where('created_at', '>=', $this->start_date);
                $query->where('created_at','<=', Carbon::parse($this->end_date)->addHour(23)->addMinute(59)->addSecond(59));
            })->get()->groupBy(function($item) {
                return $item->created_at->format('Y-m-d');
               });
username1's avatar

If I do foreach in blade the same date will appear , what I want to do is to group it which I already did in my controller and display all the data in 1 date created if there are multiple data in 1 date,

frankielee's avatar

@username1 Is this your current solution?

Sample data:

Blade:

    @foreach($jobOrders as $key =>$orders)

        @foreach ($orders as $order)
            <td>{{$order->id}}</td>
            <td> // if this the first index, show the date
            @if ($loop->first)
            {{ $key }}
            @endif
            </td>
        @endforeach
    @endforeach

Please or to participate in this conversation.