title: Laravel: Can't get uploaded images to display
body: <p>On my website, a registered user can create a post by uploading an image and writing a description. I have made it where a unique image name is created based on the user's image name and the time they upload the image. Once a name is created it is stored in the post database. The image name successfully gets stored and so does the actual image. However, when it comes to actually displaying the image on the post nothing comes up like it can't find the image. I can't seem to figure out why this is.</p>
  
  <p>Here is my PostController.php class:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  use Illuminate\Http\Request;
  
  use App\Post;
  
  class PostController extends Controller
  {
      public function getDashboard(){
          $posts = Post::orderBy('created_at', 'desc')-&gt;get();
          return view('dashboard', ['posts' =&gt; $posts]);
      }
  
      public function postCreatePost(Request $request){
          $this-&gt;validate($request, [
              'body' =&gt; 'required',
              'cover_image' =&gt; 'image|nullable|max:1999'
          ]);
  
  
          if($request-&gt;hasFile('cover_image')){
              $filenameWithExt = $request-&gt;file('cover_image')-&gt;getClientOriginalName();
              $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
              $extension = $request-&gt;file('cover_image')-&gt;getClientOriginalExtension();
              $fileNameToStore = $filename . '_' . time() . '.' . $extension; 
              $path = $request-&gt;file('cover_image')-&gt;storeAs('public/cover_images', $fileNameToStore);
          } else{
              $fileNameToStore = 'noimage.jpg';
          }
  
  
          $post = new Post(); 
          $post-&gt;body = $request['body'];
          $post-&gt;cover_image = $fileNameToStore;
          $message = 'There was an error';
          if($request-&gt;user()-&gt;posts($post)-&gt;save($post)){; //points here
              $message = 'post successfully created';
          }
          return redirect()-&gt;route('dashboard')-&gt;with(['message' =&gt; $message]);
      }
  
      public function getDeletePost($post_id){
          $post = Post::where('id', $post_id)-&gt;firstOrFail();
          $post-&gt;delete();
          return redirect()-&gt;route('dashboard')-&gt;with(['message' =&gt; 'post deleted']);
      }
  }
  </code></pre>
  
  <p>Here is my view:</p>
  
  <pre><code>&lt;section class="row new-post"&gt;
      &lt;div class="col-md-6 col-md-offset-3"&gt;
          &lt;form action="{{ route('postcreate') }}" method="post" enctype="multipart/form-data"&gt;
              &lt;div class="form-group"&gt;
                  &lt;input type="file" name="cover_image" class="form-control" id="cover_image"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;textarea class="form-control" name="body" rows="5" placeholder="your post"&gt;&lt;/textarea&gt;
              &lt;/div&gt;
              &lt;button type="submit" class="btn btn-primary"&gt;Create post&lt;/button&gt;
              &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/section&gt;
  
  
  @foreach($posts as $post)
      &lt;section class="row posts"&gt;
          &lt;div class="col-md-6"&gt;
              &lt;article class="post"&gt;
                  &lt;p&gt;{{ $post-&gt;body }}&lt;/p&gt;
                  &lt;div class="info"&gt;Posted by {{ $post-&gt;user-&gt;first_name }} {{ $post-&gt;user-&gt;last_name }} on {{ $post-&gt;created_at }}&lt;/div&gt;
                  &lt;div class="interaction"&gt;
                      &lt;a href="#" class="post-item"&gt;Like&lt;/a&gt;|
                      @if(Auth::user() == $post-&gt;user)                        
                      &lt;a href="#" class="post-item"&gt;Edit&lt;/a&gt;|
                      &lt;a href="{{ route('post.delete', ['post_id' =&gt; $post-&gt;id]) }}" class="post-item"&gt;Delete&lt;/a&gt;
                      @endif
                  &lt;/div&gt;
              &lt;/article&gt;
          &lt;/div&gt;
  
          &lt;div class="col-md-6"&gt;
              &lt;img src="/storage/cover_images/{{ $post-&gt;cover_image }}"&gt;
          &lt;/div&gt;
      &lt;/section&gt;
  @endforeach
  </code></pre>
  
  <p>Here is my migration:</p>
  
  <pre><code>    Schema::create('posts', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;timestamps();
          $table-&gt;string('cover_image');
          $table-&gt;text('body');
          $table-&gt;integer('user_id');
      });
  </code></pre>