Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add eloquent stored event generic types for collection and query builder #496

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
freekmurze marked this conversation as resolved.
Show resolved Hide resolved
*
* @extends Builder<TEloquentStoredEvent>
*/
class EloquentStoredEventQueryBuilder extends Builder
{
Expand Down
Loading