Laravel Eloquent ORM - Nested with statements
<p>So I'm creating an API for a web application I'm creating and I'm trying to keep it within the Eloquent ORM. There is a parent-child relationship that I have going on:</p>

<p>User -> Site Logs -> Sites </p>

<p>Site class code: </p>

<pre><code>class Site extends Model {
    public function log() {
        return $this-&gt;hasMany('App\SiteLog', 'site_id', 'id');
    }
}
</code></pre>

<p>SiteLog class code:</p>

<pre><code>class SiteLog extends Model
{       
    public function site()
    {
        return $this-&gt;belongsTo('App\Site', 'site_id', 'id');
    }

    public function user()
    {
        return $this-&gt;belongsTo('App\User', 'user_id', 'id');
    }
}
</code></pre>

<p>When I instantiate the SiteLog class using: </p>

<pre><code>$sites = Site::with('log')-&gt;get();
</code></pre>

<p>When I make the GET request with jQuery, I get all of the sites and inside of them I have an array of objects with all of the data for the sites respective logs. Which is exactly what I wanted. However, I wanted to take it a step further and get the user that the log is associated with.</p>

<p>Sort of like how this would work: </p>

<pre><code>SiteLog::with('user')-&gt;get();
</code></pre>

<p>But all in one statement as if it was one big join query. However, I'm not sure if the Eloquent ORM covers a test case like that. </p>

<p>Has anybody ever accomplished something like this? I can get this done with some pretty hacky practices or just writing a raw SQL query, but I am just wondering if there was a more eloquent way of doing this. </p>