File tree Expand file tree Collapse file tree 27 files changed +203
-105
lines changed Expand file tree Collapse file tree 27 files changed +203
-105
lines changed Original file line number Diff line number Diff line change @@ -53,19 +53,10 @@ trait DocumentModel
53
53
use HybridRelations;
54
54
use EmbedsRelations;
55
55
56
- /**
57
- * The collection associated with the model.
58
- *
59
- * @var string
60
- */
61
- protected $ collection ;
62
-
63
56
/**
64
57
* The parent relation instance.
65
- *
66
- * @var Relation
67
58
*/
68
- protected $ parentRelation ;
59
+ private Relation $ parentRelation ;
69
60
70
61
/**
71
62
* List of field names to unset from the document on save.
@@ -150,7 +141,7 @@ public function freshTimestamp()
150
141
/** @inheritdoc */
151
142
public function getTable ()
152
143
{
153
- return $ this ->collection ?: parent ::getTable ();
144
+ return $ this ->collection ?? parent ::getTable ();
154
145
}
155
146
156
147
/** @inheritdoc */
@@ -552,12 +543,10 @@ public function setParentRelation(Relation $relation)
552
543
553
544
/**
554
545
* Get the parent relation.
555
- *
556
- * @return Relation
557
546
*/
558
- public function getParentRelation ()
547
+ public function getParentRelation (): ? Relation
559
548
{
560
- return $ this ->parentRelation ;
549
+ return $ this ->parentRelation ?? null ;
561
550
}
562
551
563
552
/** @inheritdoc */
Original file line number Diff line number Diff line change @@ -28,7 +28,13 @@ abstract class Model extends BaseModel
28
28
*/
29
29
protected $ keyType = 'string ' ;
30
30
31
- /** @param class-string|object $related */
31
+ /**
32
+ * Indicates if the given model class is a MongoDB document model.
33
+ * It must be a subclass of {@see BaseModel} and use the
34
+ * {@see DocumentModel} trait.
35
+ *
36
+ * @param class-string|object $related
37
+ */
32
38
public static function isDocumentModel (string |object $ related ): bool
33
39
{
34
40
return is_subclass_of ($ related , BaseModel::class)
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
7
+ use Illuminate \Database \Eloquent \Model ;
8
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
8
9
use MongoDB \Laravel \Relations \EmbedsMany ;
9
10
10
- class Address extends Eloquent
11
+ class Address extends Model
11
12
{
12
- protected $ connection = 'mongodb ' ;
13
+ use DocumentModel;
14
+
15
+ protected $ primaryKey = '_id ' ;
16
+ protected $ keyType = 'string ' ;
17
+ protected $ connection = 'mongodb ' ;
13
18
protected static $ unguarded = true ;
14
19
15
20
public function addresses (): EmbedsMany
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
7
+ use Illuminate \Database \Eloquent \Model ;
8
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
8
9
9
10
/**
10
11
* @property string $name
11
12
* @property string $birthday
12
13
* @property string $time
13
14
*/
14
- class Birthday extends Eloquent
15
+ class Birthday extends Model
15
16
{
17
+ use DocumentModel;
18
+
19
+ protected $ primaryKey = '_id ' ;
20
+ protected $ keyType = 'string ' ;
16
21
protected $ connection = 'mongodb ' ;
17
- protected $ collection = 'birthday ' ;
22
+ protected string $ collection = 'birthday ' ;
18
23
protected $ fillable = ['name ' , 'birthday ' ];
19
24
20
25
protected $ casts = ['birthday ' => 'datetime ' ];
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
+ use Illuminate \Database \Eloquent \Model ;
7
8
use Illuminate \Database \Eloquent \Relations \BelongsTo ;
8
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
9
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
9
10
10
11
/**
11
12
* @property string $title
12
13
* @property string $author
13
14
* @property array $chapters
14
15
*/
15
- class Book extends Eloquent
16
+ class Book extends Model
16
17
{
17
- protected $ connection = 'mongodb ' ;
18
- protected $ collection = 'books ' ;
18
+ use DocumentModel;
19
+
20
+ protected $ primaryKey = 'title ' ;
21
+ protected $ keyType = 'string ' ;
22
+ protected $ connection = 'mongodb ' ;
23
+ protected string $ collection = 'books ' ;
19
24
protected static $ unguarded = true ;
20
- protected $ primaryKey = 'title ' ;
21
25
22
26
public function author (): BelongsTo
23
27
{
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
+ use Illuminate \Database \Eloquent \Model ;
7
8
use MongoDB \Laravel \Eloquent \Casts \ObjectId ;
8
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
9
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
9
10
10
- class CastObjectId extends Eloquent
11
+ class CastObjectId extends Model
11
12
{
12
- protected $ connection = 'mongodb ' ;
13
+ use DocumentModel;
14
+
15
+ protected $ primaryKey = '_id ' ;
16
+ protected $ keyType = 'string ' ;
17
+ protected $ connection = 'mongodb ' ;
13
18
protected static $ unguarded = true ;
14
19
protected $ casts = [
15
20
'oid ' => ObjectId::class,
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
+ use Illuminate \Database \Eloquent \Model ;
7
8
use MongoDB \Laravel \Eloquent \Casts \BinaryUuid ;
8
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
9
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
9
10
10
- class Casting extends Eloquent
11
+ class Casting extends Model
11
12
{
13
+ use DocumentModel;
14
+
15
+ protected $ primaryKey = '_id ' ;
16
+ protected $ keyType = 'string ' ;
12
17
protected $ connection = 'mongodb ' ;
13
- protected $ collection = 'casting ' ;
18
+ protected string $ collection = 'casting ' ;
14
19
15
20
protected $ fillable = [
16
21
'uuid ' ,
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
+ use Illuminate \Database \Eloquent \Model ;
7
8
use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
8
9
use Illuminate \Database \Eloquent \Relations \HasMany ;
9
10
use Illuminate \Database \Eloquent \Relations \MorphOne ;
10
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
11
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
11
12
12
- class Client extends Eloquent
13
+ class Client extends Model
13
14
{
14
- protected $ connection = 'mongodb ' ;
15
- protected $ collection = 'clients ' ;
15
+ use DocumentModel;
16
+
17
+ protected $ primaryKey = '_id ' ;
18
+ protected $ keyType = 'string ' ;
19
+ protected $ connection = 'mongodb ' ;
20
+ protected string $ collection = 'clients ' ;
16
21
protected static $ unguarded = true ;
17
22
18
23
public function users (): BelongsToMany
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
+ use Illuminate \Database \Eloquent \Model ;
7
8
use Illuminate \Database \Eloquent \Relations \MorphToMany ;
8
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
9
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
9
10
10
- class Experience extends Eloquent
11
+ class Experience extends Model
11
12
{
12
- protected $ connection = 'mongodb ' ;
13
- protected $ collection = 'experiences ' ;
13
+ use DocumentModel;
14
+
15
+ protected $ primaryKey = '_id ' ;
16
+ protected $ keyType = 'string ' ;
17
+ protected $ connection = 'mongodb ' ;
18
+ protected string $ collection = 'experiences ' ;
14
19
protected static $ unguarded = true ;
15
20
16
21
protected $ casts = ['years ' => 'int ' ];
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
+ use Illuminate \Database \Eloquent \Model ;
7
8
use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
8
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
9
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
9
10
10
- class Group extends Eloquent
11
+ class Group extends Model
11
12
{
12
- protected $ connection = 'mongodb ' ;
13
- protected $ collection = 'groups ' ;
13
+ use DocumentModel;
14
+
15
+ protected $ primaryKey = '_id ' ;
16
+ protected $ keyType = 'string ' ;
17
+ protected $ connection = 'mongodb ' ;
18
+ protected string $ collection = 'groups ' ;
14
19
protected static $ unguarded = true ;
15
20
16
21
public function users (): BelongsToMany
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
7
+ use Illuminate \Database \Eloquent \Model ;
8
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
8
9
9
- class Guarded extends Eloquent
10
+ class Guarded extends Model
10
11
{
12
+ use DocumentModel;
13
+
14
+ protected $ primaryKey = '_id ' ;
15
+ protected $ keyType = 'string ' ;
11
16
protected $ connection = 'mongodb ' ;
12
- protected $ collection = 'guarded ' ;
13
- protected $ guarded = ['foobar ' , 'level1->level2 ' ];
17
+ protected string $ collection = 'guarded ' ;
18
+ protected $ guarded = ['foobar ' , 'level1->level2 ' ];
14
19
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
+ use Illuminate \Database \Eloquent \Model ;
8
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
7
9
use MongoDB \Laravel \Eloquent \Model as Eloquent ;
8
10
use MongoDB \Laravel \Query \Builder ;
9
11
16
18
* @method static Builder truncate()
17
19
* @method static Eloquent sole(...$parameters)
18
20
*/
19
- final class HiddenAnimal extends Eloquent
21
+ final class HiddenAnimal extends Model
20
22
{
23
+ use DocumentModel;
24
+
25
+ protected $ primaryKey = '_id ' ;
26
+ protected $ keyType = 'string ' ;
21
27
protected $ fillable = [
22
28
'name ' ,
23
29
'country ' ,
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
+ use Illuminate \Database \Eloquent \Model ;
7
8
use MongoDB \Laravel \Eloquent \Casts \BinaryUuid ;
8
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
9
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
9
10
10
- class IdIsBinaryUuid extends Eloquent
11
+ class IdIsBinaryUuid extends Model
11
12
{
12
- protected $ connection = 'mongodb ' ;
13
+ use DocumentModel;
14
+
15
+ protected $ primaryKey = '_id ' ;
16
+ protected $ keyType = 'string ' ;
17
+ protected $ connection = 'mongodb ' ;
13
18
protected static $ unguarded = true ;
14
- protected $ casts = [
19
+ protected $ casts = [
15
20
'_id ' => BinaryUuid::class,
16
21
];
17
22
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
7
+ use Illuminate \Database \Eloquent \Model ;
8
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
8
9
9
- class IdIsInt extends Eloquent
10
+ class IdIsInt extends Model
10
11
{
11
- protected $ keyType = 'int ' ;
12
- protected $ connection = 'mongodb ' ;
12
+ use DocumentModel;
13
+
14
+ protected $ primaryKey = '_id ' ;
15
+ protected $ keyType = 'int ' ;
16
+ protected $ connection = 'mongodb ' ;
13
17
protected static $ unguarded = true ;
14
- protected $ casts = ['_id ' => 'int ' ];
18
+ protected $ casts = ['_id ' => 'int ' ];
15
19
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
7
+ use Illuminate \Database \Eloquent \Model ;
8
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
8
9
9
- class IdIsString extends Eloquent
10
+ class IdIsString extends Model
10
11
{
11
- protected $ connection = 'mongodb ' ;
12
+ use DocumentModel;
13
+
14
+ protected $ primaryKey = '_id ' ;
15
+ protected $ keyType = 'string ' ;
16
+ protected $ connection = 'mongodb ' ;
12
17
protected static $ unguarded = true ;
13
- protected $ casts = ['_id ' => 'string ' ];
18
+ protected $ casts = ['_id ' => 'string ' ];
14
19
}
Original file line number Diff line number Diff line change 5
5
namespace MongoDB \Laravel \Tests \Models ;
6
6
7
7
use Carbon \Carbon ;
8
+ use Illuminate \Database \Eloquent \Model ;
8
9
use Illuminate \Database \Eloquent \Relations \BelongsTo ;
9
10
use MongoDB \Laravel \Eloquent \Builder ;
10
- use MongoDB \Laravel \Eloquent \Model as Eloquent ;
11
+ use MongoDB \Laravel \Eloquent \DocumentModel ;
11
12
12
13
/** @property Carbon $created_at */
13
- class Item extends Eloquent
14
+ class Item extends Model
14
15
{
15
- protected $ connection = 'mongodb ' ;
16
- protected $ collection = 'items ' ;
16
+ use DocumentModel;
17
+
18
+ protected $ primaryKey = '_id ' ;
19
+ protected $ keyType = 'string ' ;
20
+ protected $ connection = 'mongodb ' ;
21
+ protected string $ collection = 'items ' ;
17
22
protected static $ unguarded = true ;
18
23
19
24
public function user (): BelongsTo
You can’t perform that action at this time.
0 commit comments