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

[10.x] Add the ability to extend the generic types for DatabaseNotificationCollection #47048

Merged
merged 7 commits into from
May 12, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

use Illuminate\Database\Eloquent\Collection;

/**
* @template TKey of array-key
* @template TModel of DatabaseNotification
*
* @extends \Illuminate\Database\Eloquent\Collection<TKey, TModel>
*/
class DatabaseNotificationCollection extends Collection
{
/**
Expand Down
25 changes: 25 additions & 0 deletions types/Notifications/DatabaseNotificationCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Notifications\DatabaseNotificationCollection;

use function PHPStan\Testing\assertType;

class CustomNotification extends DatabaseNotification
{
//
}

/**
* @extends DatabaseNotificationCollection<int, CustomNotification>
*/
class CustomNotificationCollection extends DatabaseNotificationCollection
{
//
}

$databaseNotificationsCollection = DatabaseNotification::all();
assertType('Illuminate\Database\Eloquent\Collection<int, Illuminate\Notifications\DatabaseNotification>', $databaseNotificationsCollection);

$customNotificationsCollection = CustomNotification::all();
assertType('Illuminate\Database\Eloquent\Collection<int, CustomNotification>', $customNotificationsCollection);