title: Add an profile image next to an post corresponding to the user in Laravel 5.7
body: <p>I was trying to make that when there was a post made by user <code>John whit</code> <code>user_id</code> 1<br>
  It check if he has an profile and if he has an profile it puts the image next to it that corresponds to the user and the profile he or she created. so when I login whit the user it works fine because I'm getting the user id out of </p>
  
  <pre><code>   Auth::user()-&gt;id 
  </code></pre>
  
  <p>But when I log in whit another user and look at the page I get off an error.  </p>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
    <p>Trying to get property 'id' of non-object (View: 
       C:\Users\Merlijn\AppData\Roaming\Composer\Laravel 
       Projects\blog\resources\views\posts\post.blade.php) (View: 
       C:\Users\Merlijn\AppData\Roaming\Composer\Laravel 
       Projects\blog\resources\views\posts\post.blade.php)</p>
  </blockquote>
  
  <p>so mine question is How can I make that the Image that belongs to the user is connected to the post the user image and post are in 3 different tables.
  here how I try to do it now?</p>
  
  <p><strong>Post.blade.php</strong></p>
  
  <pre><code>&lt;div class="blog-post"&gt;
  
    &lt;h2 class="blog-post-title"&gt;
  
      &lt;a href="{{ route('posts.show', ["post" =&gt; $post-&gt;id]) }}"&gt;
  
       {{ $post-&gt;title }}
  
      &lt;/a&gt;
  
  &lt;/h2&gt;
  
  &lt;p class="blog-post-meta"&gt;
  
      @foreach($image as $path)
          @if(Auth::user()-&gt;id == $path-&gt;user_id)
          {{--{{dd($path)}}--}}
              @if(!$path-&gt;image_path == null)
                  &lt;img src="/images/{{ $path-&gt;image_path }}" id="imgProfile" style="width: 150px; height: 150px" class="img-thumbnail" /&gt;
              @else
                  &lt;img src="http://placehold.it/150x150"   id="imgProfile" style="width: 150px; height: 150px" class="img-thumbnail" /&gt;
              @endif
          @endif
      @endforeach
  
      &lt;a href="#"&gt;{{ $post-&gt;user-&gt;name }}&lt;/a&gt; on
  
      {{ $post-&gt;created_at-&gt;toFormattedDateString() }}
  
  &lt;/p&gt;
  
  &lt;p&gt;
      {{
      $post-&gt;body
      }}
  &lt;/p&gt;
  
  &lt;br&gt;
  
  @if (Auth::check())
  
      @if(Auth::user()-&gt;id == $post-&gt;user_id)
      &lt;div class="button-box col-lg-12"&gt;
  
          &lt;a href="{{ route('posts.edit', ["post" =&gt; $post-&gt;id]) }}" class="btn btn-info" role="button"&gt;Edit&lt;/a&gt;
          &lt;a href="{{ route('posts.delete', ["post" =&gt; $post-&gt;id]) }}" class="btn btn-info" role="button"&gt;Delete&lt;/a&gt;
  
      &lt;/div&gt;
  
      @endif
  
  @endif
  
  &lt;hr&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>AppService provider</strong></p>
  
  <pre><code>&lt;?php
  
    namespace App\Providers;
  
   use Illuminate\Support\Facades\Schema;
   use Illuminate\Support\ServiceProvider;
   use View;
   use App\Profile;
  
   class AppServiceProvider extends ServiceProvider
  {
  
  public function boot()
  {
      Schema::defaultStringLength(191);
  
      view()-&gt;composer('layouts.sidebar', function($view){
  
          $view-&gt;with('archives', \App\Post::archives());
  
      });
  
      View::share('image', Profile::all());
  }
  
  /**
   * Register any application services.
   *
   * @return void
   */
  public function register()
  {
      //
  }
   }
  </code></pre>
  
  <p>If u need anything like extra information note it and I will edit it in</p>