P
P
Programmir2017-03-21 08:34:23
Laravel
Programmir, 2017-03-21 08:34:23

When should and should not parentheses be used in relations?

For example, we have an association of authors with posts. You can write like this in laravel
$author->post()
and like this
$author->post
The documentation just says what can be a dynamic property.
Can someone clarify this point?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Melikhov, 2017-03-21
@amelihovv


$author->post()
returns the query builder, so you can continue calling the query builder's methods, e.g.
And in the second case, you immediately get a model or a collection of models.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question