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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -