When I use ModelName::with('somerelation')->get()
with Laravel Eloquent, if the model doesn't have this relationship I get Call to undefined relationship [somerelation] on model [App\SomeModel]
error.
But for polymorphic relations, I get collection of all related models and I would like to use with('somerelation')
and get null
if relationship is not defined. Is there any way to avoid error and return null from with() or any way to use with conditionally?