File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -656,7 +656,7 @@ public function getImageUrl()
656656 return Storage::disk ('public ' )->url (app ('assets_upload_path ' ).e ($ this ->image ));
657657 } elseif ($ this ->model && ! empty ($ this ->model ->image )) {
658658 return Storage::disk ('public ' )->url (app ('models_upload_path ' ).e ($ this ->model ->image ));
659- } elseif ($ this ->model ->category && ! empty ($ this ->model ->category ->image )) {
659+ } elseif ($ this ->model ? ->category && ! empty ($ this ->model ->category ->image )) {
660660 return Storage::disk ('public ' )->url (app ('categories_upload_path ' ).e ($ this ->model ->category ->image ));
661661 }
662662
Original file line number Diff line number Diff line change @@ -199,4 +199,43 @@ public function testAssignedTypeWithoutAssignTo()
199199 ]);
200200 $ this ->assertModelMissing ($ asset );
201201 }
202+
203+ public function testGetImageUrlMethod ()
204+ {
205+ $ urlBase = config ('filesystems.disks.public.url ' );
206+
207+ $ category = Category::factory ()->create (['image ' => 'category-image.jpg ' ]);
208+ $ model = AssetModel::factory ()->for ($ category )->create (['image ' => 'asset-model-image.jpg ' ]);
209+ $ asset = Asset::factory ()->for ($ model , 'model ' )->create (['image ' => 'asset-image.jpg ' ]);
210+
211+ $ this ->assertEquals (
212+ "{$ urlBase }/assets/asset-image.jpg " ,
213+ $ asset ->getImageUrl ()
214+ );
215+
216+ $ asset ->update (['image ' => null ]);
217+
218+ $ this ->assertEquals (
219+ "{$ urlBase }/models/asset-model-image.jpg " ,
220+ $ asset ->refresh ()->getImageUrl ()
221+ );
222+
223+ $ model ->update (['image ' => null ]);
224+
225+ $ this ->assertEquals (
226+ "{$ urlBase }/categories/category-image.jpg " ,
227+ $ asset ->refresh ()->getImageUrl ()
228+ );
229+
230+ $ category ->image = null ;
231+ $ category ->save ();
232+
233+ $ this ->assertFalse ($ asset ->refresh ()->getImageUrl ());
234+
235+ // handles case where model does not exist
236+ $ asset ->model_id = 9999999 ;
237+ $ asset ->forceSave ();
238+
239+ $ this ->assertFalse ($ asset ->refresh ()->getImageUrl ());
240+ }
202241}
You can’t perform that action at this time.
0 commit comments