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

vassie98's avatar

List ALL days between a startdate and enddate IF any of these days are found in a CarbonPeriod

Hello,

I've started using laravel since almost a month ago for a customer of mine. I've never used it before and I've learned a lot since then. I'm close to completion but I'm stuck at a problem.

The application allows employees to enter startdates and enddates in which they are on vacation. I got all that working and too be honest I'm proud of myself :)

However I also got an admin page in which my client has multiple overviews of these dates. All of them work except one; a daily overview.

The goal is to have a preview of the upcoming 30 days and show all the days where someone is on a vaction (or not)

Right now I've managed to group the starting days. So now it shows nothing on the page except for which holidays start on, for example, 12th of may. What I want is if someone fills in 10th - 15th may, it should show all those days. And if someone also have some of those days group them together and show them per day. Kinda just like it does now with the starting days.

Apologies if I'm maybe not clear enough. I've been at this nonstop for 3 working days and I'm exhausted.

I'm hoping that somebody can point me in the right direction here because I'm lost. Below you will find my best attempt so far.

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
use App\Models\Event;

class AdminController extends Controller
{
    public function index(Request $request)
    {
        $events = DB::table('events')->get();
// Create period (I'm not using this right now but I think I'm gonna have to use this somehow?)
        $period = CarbonPeriod::create(now(), now()->addDays(30))->toArray();

// This I stole from google. This groups all events by start (table column name) which works nicely. However now I want all the days between start and end
        $days = Event::whereBetween('start', [now(), now()->addDays(30)])
            ->orderBy('start')
            ->get()
            ->groupBy(function ($val) {
                return Carbon::parse($val->start)->translatedFormat('l j F');
            });

        return view('admin', [
            'events' => $events,
            'days' => $days,
            'period' => $period,
        ]);
    }
}

And on the website I show it like this:

@foreach ($days as $day => $dailyEvents)
    <h2>{{ $day }}</h2>
    @foreach ($dailyEvents as $event)
        // show stuff here
    @endforeach
@endforeach
0 likes
1 reply

Please or to participate in this conversation.