eloquent - Using Laravel's ORM - what's the difference between the longhand and the shorthand? -
for instance:
return product::first()->baseproduct->products
works, whereas
return product::first()->baseproduct()->products()
does not, , badmethodcallexception
.
i understand there's notable difference, then, between 2 lines, difference, , how work?
i'm assuming baseproduct() , products() both relationships in models? calling products() won't return eloquent objects, it'll return hasmany or belongstomany (children of relation) object.
calling products instead of products() triggers magic method. magic calls getresults() method on relation object. way collection of product models. typically way should work relationships.
in other words:
baseproduct::first()->products == baseproduct::first()->products()->getresults()
i suggest have @ source code
Comments
Post a Comment