Skip to content

Commit

Permalink
[10.x] Add the ability to extend the generic types for DatabaseNotifi…
Browse files Browse the repository at this point in the history
…cationCollection (laravel#47048)

* Add the ability to extend the generic types

* Update DatabaseNotificationCollection.php

* Remove unused

* Add tests

* Fix style

* rm lb

* Updates localtion of type tests

---------

Co-authored-by: Nuno Maduro <[email protected]>
  • Loading branch information
2 people authored and milwad-dev committed May 12, 2023
1 parent 3ba111e commit 56c9c7d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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);

0 comments on commit 56c9c7d

Please sign in to comment.