Skip to content

Commit 89463b0

Browse files
authored
Create DocumentModel trait to enable MongoDB on any 3rd party model class (#2580)
* Create DocumentModel trait to enable MongoDB on any 3rd party model class * Use the trait for every test model * Add method Model::isDocumentModel to check when model classes can be used with MongoDB * Refactor the User class to extend Laravel's User class
1 parent ffacc6b commit 89463b0

40 files changed

+1086
-887
lines changed

CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [4.5.0] - upcoming
4+
## [4.6.0] - upcoming
55

6-
* Add GridFS integration for Laravel File Storage by @GromNaN in [#2984](https://github.com/mongodb/laravel-mongodb/pull/2985)
6+
* Add `DocumentTrait` to use any 3rd party model with MongoDB @GromNaN in [#2580](https://github.com/mongodb/laravel-mongodb/pull/2580)
7+
8+
## [4.5.0] - 2024-06-20
9+
10+
* Add GridFS integration for Laravel File Storage by @GromNaN in [#2985](https://github.com/mongodb/laravel-mongodb/pull/2985)
711

812
## [4.4.0] - 2024-05-31
913

phpstan-baseline.neon

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ parameters:
77

88
-
99
message: "#^Method Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:push\\(\\) invoked with 3 parameters, 0 required\\.$#"
10-
count: 2
10+
count: 3
1111
path: src/Relations/BelongsToMany.php
1212

1313
-
1414
message: "#^Method Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:push\\(\\) invoked with 3 parameters, 0 required\\.$#"
15-
count: 2
15+
count: 6
1616
path: src/Relations/MorphToMany.php
1717

1818
-

src/Auth/User.php

+7-16
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,13 @@
44

55
namespace MongoDB\Laravel\Auth;
66

7-
use Illuminate\Auth\Authenticatable;
8-
use Illuminate\Auth\MustVerifyEmail;
9-
use Illuminate\Auth\Passwords\CanResetPassword;
10-
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
11-
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
12-
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
13-
use Illuminate\Foundation\Auth\Access\Authorizable;
14-
use MongoDB\Laravel\Eloquent\Model;
7+
use Illuminate\Foundation\Auth\User as BaseUser;
8+
use MongoDB\Laravel\Eloquent\DocumentModel;
159

16-
class User extends Model implements
17-
AuthenticatableContract,
18-
AuthorizableContract,
19-
CanResetPasswordContract
10+
class User extends BaseUser
2011
{
21-
use Authenticatable;
22-
use Authorizable;
23-
use CanResetPassword;
24-
use MustVerifyEmail;
12+
use DocumentModel;
13+
14+
protected $primaryKey = '_id';
15+
protected $keyType = 'string';
2516
}

0 commit comments

Comments
 (0)