retrieve all records with laravel eloquent
<p>I tried following the docs <a href="https://laravel.com/docs/5.3/eloquent-relationships" rel="nofollow noreferrer">here</a> but didn't get the desired result,
My tables looks like</p>

<p>users table</p>

<pre><code>id (pk - int) | username,
</code></pre>

<p>tweets table</p>

<pre><code>id (pk - int) | user_id (fk - int) | tweet(varchar)
</code></pre>

<p>User Model</p>

<pre><code>public function tweets() {
   return $this-&gt;hasMany('App\Tweet', 'user_id); // user_id is FK
}
</code></pre>

<p>Tweet Model</p>

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

<p>And on the controller side, I'am using eloquent to retrieve data. I have this method, </p>

<pre><code>public function ajax($id) {
    $data = User::with('tweets')-&gt;find($id)-&gt;tweets();
    return $data;
}
</code></pre>

<p>I tried following the logic <a href="https://stackoverflow.com/questions/25108536/how-to-retrieve-all-records-by-foreign-key-with-laravel">here</a> but I'm getting the following error on the controller code:</p>

<blockquote>
  <p>Trying to get property of non-object </p>
</blockquote>