Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
trippo committed Aug 29, 2024
1 parent c854879 commit 2612e22
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Traits/HasOpeningHours.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@

use Carbon\Carbon;
use DateTimeInterface;
use Datomatic\DatabaseOpeningHours\Models\OpeningHour;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;

/**
* @method static \Illuminate\Database\Eloquent\Builder|static openAt(string|DateTimeInterface $date)
* @method static \Illuminate\Database\Eloquent\Builder|static closeAt(string|DateTimeInterface $date)
*/
trait HasOpeningHours
{
public function openingHours(): MorphMany
{
return $this->morphMany(OpeningHour::class, 'openable');
}

public function latestOpeningHours(): MorphOne
{
return $this->morphOne(OpeningHour::class, 'openable')->latestOfMany();
}

public function oldestOpeningHours(): MorphOne
{
return $this->morphOne(OpeningHour::class, 'openable')->oldestOfMany();
}

public function scopeOpenAt(Builder $query, string|DateTimeInterface $date): void
{
if (! $date instanceof Carbon) {
Expand Down

0 comments on commit 2612e22

Please sign in to comment.