Laravel 5, Trying to get property of non-object
<p>My Controller :</p>

<pre><code> public function show($id){
    $user_id_1_connections = Connection::whereUser_id_1AndConnection_status($id, 1)-&gt;get();
    $user_id_2_connections = Connection::whereUser_id_2AndConnection_status($id, 1)-&gt;get();
    return view('connection.showConnection',['user_id_1_connections' =&gt; $user_id_1_connections, 'user_id_2_connections' =&gt; $user_id_2_connections]);
} 
</code></pre>

<p>My Model : </p>

<pre><code>protected $table = 'connections';
protected $fillable = ['user_id_1','user_id_2','connection_status'];

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

<p>My Blade :</p>

<pre><code>@foreach($user_id_1_connections as $user_id_1_connection)
{{ $user_id_1_connection-&gt;user-&gt;name }}
{{ $comment-&gt;user-&gt;name }}
@endforeach
@foreach($user_id_2_connections as $user_id_2_connection)
{{ $user_id_2_connection-&gt;user-&gt;name }}
@endforeach
</code></pre>

<p>I have made foreign key to user_id_1 and user_id_2 to users table.</p>

<pre><code>$table-&gt;integer('user_id_1')-&gt;unsigned();
        $table-&gt;foreign('user_id_1')-&gt;references('id')-&gt;on('users')-&gt;onDelete('cascade');
        $table-&gt;integer('user_id_2')-&gt;unsigned();
        $table-&gt;foreign('user_id_2')-&gt;references('id')-&gt;on('users')-&gt;onDelete('cascade');
</code></pre>

<p>But when I'm running this code. It's showing the error :
Trying to get property of non-object.</p>