Skip to content

Commit

Permalink
Merge pull request #496 from maartenpaauw/feature/eloquent-generic-ty…
Browse files Browse the repository at this point in the history
…pings

feat: add eloquent stored event generic types for collection and query builder
  • Loading branch information
freekmurze authored Jan 22, 2025
2 parents 12028ba + 9318efb commit f56f4dc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/StoredEvents/Models/EloquentStoredEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ public function getMetaDataAttribute(): SchemalessAttributes
return SchemalessAttributes::createForModel($this, 'meta_data');
}

/**
* @return EloquentStoredEventQueryBuilder<$this>
*/
public function newEloquentBuilder($query): EloquentStoredEventQueryBuilder
{
return new EloquentStoredEventQueryBuilder($query);
}

/**
* @return EloquentStoredEventCollection<$this>
*/
public function newCollection(array $models = []): EloquentStoredEventCollection
{
return new EloquentStoredEventCollection($models);
Expand Down
5 changes: 5 additions & 0 deletions src/StoredEvents/Models/EloquentStoredEventCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;

/**
* @template TEloquentStoredEvent of EloquentStoredEvent
*
* @extends EloquentCollection<array-key, TEloquentStoredEvent>
*/
class EloquentStoredEventCollection extends EloquentCollection
{
/**
Expand Down
6 changes: 5 additions & 1 deletion src/StoredEvents/Models/EloquentStoredEventQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
use Spatie\EventSourcing\StoredEvents\StoredEvent;

/**
* @method \Spatie\EventSourcing\StoredEvents\Models\EloquentStoredEventCollection get
* @template TEloquentStoredEvent of EloquentStoredEvent
*
* @method \Spatie\EventSourcing\StoredEvents\Models\EloquentStoredEventCollection<EloquentStoredEvent> get()
*
* @extends Builder<TEloquentStoredEvent>
*/
class EloquentStoredEventQueryBuilder extends Builder
{
Expand Down

0 comments on commit f56f4dc

Please sign in to comment.