PHP code example of boysfromthefactory / groundhog

1. Go to this page and download the library: Download boysfromthefactory/groundhog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

boysfromthefactory / groundhog example snippets


return [
    // ISO-8601 duration: how far an infinite rule is expanded after the query's lower start
    // bound (or after now) when the query gives no upper bound.
    'horizon' => 'P1Y',

    // Most occurrences one series may generate for one query (or on save); more fails with
    // OccurrenceLimitExceeded.
    'max_occurrences_per_series' => 50000,
];

use BoysFromTheFactory\Groundhog\Concerns\HasRecurrence;
use Illuminate\Database\Eloquent\Model;

class Meeting extends Model
{
    use HasRecurrence;

    // Only needed when your columns are named differently (defaults shown).
    public const RECURRENCE_STARTS_AT = 'starts_at';
    public const RECURRENCE_ENDS_AT = 'ends_at'; // null when the model has no end column

    protected $fillable = ['title', 'starts_at', 'ends_at', 'recurrence_rule'];
}

Meeting::create([
    'title' => 'Standup',
    'starts_at' => '2026-03-02 09:00',
    'ends_at' => '2026-03-02 10:00',
    'recurrence_rule' => 'FREQ=WEEKLY;BYDAY=MO',
]);

$meeting->recurrence_rule->humanReadable(); // "weekly on Monday, starting from 3/2/26, forever"
$meeting->recurrence_rule->getOccurrencesBetween('2026-03-01', '2026-03-31');

Meeting::whereBetween('starts_at', [$from, $to])
    ->where('location', 'Room A')
    ->orderBy('starts_at')
    ->paginate(25);

$occurrence->isVirtualOccurrence();     // true
$occurrence->series;                    // the stored series record
$occurrence->originalOccurrenceStart(); // the start the rule generated

$occurrence->update(['location' => 'Room B']); // stored as an exception of this occurrence only
$occurrence->delete();                          // cancels this occurrence; nothing is stored
bash
composer vendor:publish --tag="groundhog-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="groundhog-config"