@@ -127,6 +127,8 @@ public function testStrictModeWithCustomCallbackOnLazyLoading()
127127 $ models = EloquentStrictLoadingTestModel1::get ();
128128
129129 $ models [0 ]->modelTwos ;
130+
131+ Model::handleLazyLoadingViolationUsing (null );
130132 }
131133
132134 public function testStrictModeWithOverriddenHandlerOnLazyLoading ()
@@ -141,6 +143,21 @@ public function testStrictModeWithOverriddenHandlerOnLazyLoading()
141143
142144 $ models [0 ]->modelTwos ;
143145 }
146+
147+ public function testStrictModeDoesntThrowAnExceptionOnManuallyMadeModel ()
148+ {
149+ $ model1 = EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading::make ();
150+ $ model2 = EloquentStrictLoadingTestModel2::make ();
151+ $ model1 ->modelTwos ->push ($ model2 );
152+
153+ $ this ->assertInstanceOf (Collection::class, $ model1 ->modelTwos );
154+ }
155+
156+ public function testStrictModeDoesntThrowAnExceptionOnRecentlyCreatedModel ()
157+ {
158+ $ model1 = EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading::create ();
159+ $ this ->assertInstanceOf (Collection::class, $ model1 ->modelTwos );
160+ }
144161}
145162
146163class EloquentStrictLoadingTestModel1 extends Model
@@ -172,6 +189,19 @@ protected function handleLazyLoadingViolation($key)
172189 }
173190}
174191
192+ class EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading extends Model
193+ {
194+ public $ table = 'test_model1 ' ;
195+ public $ timestamps = false ;
196+ public $ preventsLazyLoading = true ;
197+ protected $ guarded = [];
198+
199+ public function modelTwos ()
200+ {
201+ return $ this ->hasMany (EloquentStrictLoadingTestModel2::class, 'model_1_id ' );
202+ }
203+ }
204+
175205class EloquentStrictLoadingTestModel2 extends Model
176206{
177207 public $ table = 'test_model2 ' ;
0 commit comments