Search code examples
laravelrelationships

Relations retrieval difference in Laravel


Whats the difference between

$this->translations;

and

$this->translations()->get();

where translations is the relationship of the current model. I thought both do the same thing.


Solution

  • They are basically the same thing.

    However:

    • $this->translations()->get(); will query the database every time this is called.
    • $this->translations; will execute the database query the first time and will store the result in memory for later use.