File tree 5 files changed +55
-8
lines changed
5 files changed +55
-8
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ Table of contents
11
11
* [ Upgrading] ( #upgrading )
12
12
* [ Configuration] ( #configuration )
13
13
* [ Eloquent] ( #eloquent )
14
+ * [ Guarding attributes] ( #guarding-attributes )
14
15
* [ Optional: Alias] ( #optional-alias )
15
16
* [ Query Builder] ( #query-builder )
16
17
* [ Schema] ( #schema )
@@ -41,6 +42,7 @@ composer require jenssegers/mongodb
41
42
5.2.x | 2.3.x or 3.0.x
42
43
5.3.x | 3.1.x or 3.2.x
43
44
5.4.x | 3.2.x
45
+ 5.5.x | 3.3.x
44
46
45
47
And add the service provider in ` config/app.php ` :
46
48
@@ -192,6 +194,13 @@ class MyModel extends Eloquent {
192
194
193
195
Everything else (should) work just like the original Eloquent model. Read more about the Eloquent on http://laravel.com/docs/eloquent
194
196
197
+ ### Guarding attributes
198
+
199
+ When choosing between guarding attributes or marking some as fillable, Taylor Otwell prefers the fillable route.
200
+ This is in light of [ recent security issues described here] ( https://blog.laravel.com/security-release-laravel-61835-7240 ) .
201
+
202
+ Keep in mind guarding still works, but you may experience unexpected behavior.
203
+
195
204
### Optional: Alias
196
205
197
206
You may also register an alias for the MongoDB model by adding the following to the alias array in ` config/app.php ` :
Original file line number Diff line number Diff line change @@ -420,6 +420,17 @@ protected function removeTableFromKey($key)
420
420
return $ key ;
421
421
}
422
422
423
+ /**
424
+ * Checks if column exists on a table. As this is a document model, just return true. This also
425
+ * prevents calls to non-existent function Grammar::compileColumnListing()
426
+ * @param string $key
427
+ * @return bool
428
+ */
429
+ protected function isGuardableColumn ($ key )
430
+ {
431
+ return true ;
432
+ }
433
+
423
434
/**
424
435
* @inheritdoc
425
436
*/
Original file line number Diff line number Diff line change 7
7
8
8
class Builder extends \Illuminate \Database \Schema \Builder
9
9
{
10
- /**
11
- * @inheritdoc
12
- */
13
- public function __construct (Connection $ connection )
14
- {
15
- $ this ->connection = $ connection ;
16
- }
17
-
18
10
/**
19
11
* @inheritdoc
20
12
*/
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public function tearDown()
14
14
Soft::truncate ();
15
15
Book::truncate ();
16
16
Item::truncate ();
17
+ Guarded::truncate ();
17
18
}
18
19
19
20
public function testNewModel ()
@@ -548,4 +549,27 @@ public function testChunkById()
548
549
549
550
$ this ->assertEquals (3 , $ count );
550
551
}
552
+
553
+ public function testGuardedModel ()
554
+ {
555
+ $ model = new Guarded ();
556
+
557
+ // foobar is properly guarded
558
+ $ model ->fill (['foobar ' => 'ignored ' , 'name ' => 'John Doe ' ]);
559
+ $ this ->assertFalse (isset ($ model ->foobar ));
560
+ $ this ->assertSame ('John Doe ' , $ model ->name );
561
+
562
+ // foobar is guarded to any level
563
+ $ model ->fill (['foobar->level2 ' => 'v2 ' ]);
564
+ $ this ->assertNull ($ model ->getAttribute ('foobar->level2 ' ));
565
+
566
+ // multi level statement also guarded
567
+ $ model ->fill (['level1->level2 ' => 'v1 ' ]);
568
+ $ this ->assertNull ($ model ->getAttribute ('level1->level2 ' ));
569
+
570
+ // level1 is still writable
571
+ $ dataValues = ['array ' , 'of ' , 'values ' ];
572
+ $ model ->fill (['level1 ' => $ dataValues ]);
573
+ $ this ->assertEquals ($ dataValues , $ model ->getAttribute ('level1 ' ));
574
+ }
551
575
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ use Jenssegers \Mongodb \Eloquent \Model as Eloquent ;
5
+
6
+ class Guarded extends Eloquent
7
+ {
8
+ protected $ connection = 'mongodb ' ;
9
+ protected $ collection = 'guarded ' ;
10
+ protected $ guarded = ['foobar ' , 'level1->level2 ' ];
11
+ }
You can’t perform that action at this time.
0 commit comments