1 week ago

How does cmgmyr/messenger do what it does??

Posted 1 week ago by mforcella

I am currently working on a project and using cmgmyr/messenger. It's a terrific service, but using it has made me realize how much functionality exists within Laravel/Eloquent that I am not taking advantage of. I have a specific question regarding retrieving Threads, as per the example code provided here:

The show() method retrieves a Thread via "$thread = Thread::findOrFail($id)"

The index() method retrieves Threads via "$threads = Thread::forUser(Auth::id())->latest('updated_at')->get()"

My question relates to the data that is being pulled by these methods. If I were to Log the $thread object after either of these function calls, I only see the expected columns from the thread table. However, once these results are passed to, and rendered by, a blade template, there is additional data included in the $thread object.

In the case of the index() template, when I call console.log on the $thread object, I see that it also includes the User objects associated with each Thread. In the case of the show() template, I see that it also includes the Message objects associated with the Thread.

So my question is, what is the mechanism at work here, and how can I leverage it in my other models?

Please sign in or create an account to participate in this conversation.