title: show image file in browser after uploading in laravel database
body: <p>I have a create form with some field like;name, price,category,... and a input field for image file.</p>
  
  <p>it's my create.blade.php :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@extends('layouts.app')
  @section('content')
      &lt;div class="container"&gt;
  
          &lt;div class="card mt-5"&gt;
              &lt;div class="card-body"&gt;
                  &lt;div class="card-title"&gt;
                      create product
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;form method="post" action="{{route('books.store')}}" enctype="multipart/form-data"&gt;
              {{csrf_field()}}
              &lt;div class="form-group"&gt;
                  &lt;label for="name"&gt;Name&lt;/label&gt;
                  &lt;input type="text" class="form-control" name="name" id="name" aria-describedby="emailHelp" value="{{old('name')}}" placeholder="Enter name"&gt;
  
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="pages"&gt;pages&lt;/label&gt;
                  &lt;input type="text" class="form-control" id="pages" name="pages" value="{{old('pages')}}" placeholder="pages"&gt;
              &lt;/div&gt;
  
  
  
              &lt;div class="form-group"&gt;
                  &lt;label for="ISBN"&gt;ISBN&lt;/label&gt;
                  &lt;input type="text" class="form-control" id="ISBN" name="ISBN" value="{{old('ISBN')}}" placeholder="ISBN"&gt;
              &lt;/div&gt;
  
  
              &lt;div class="form-group"&gt;
                  &lt;label for="price"&gt;price&lt;/label&gt;
                  &lt;input type="text" class="form-control" id="price" name="price" value="{{old('price')}}" placeholder="price"&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;label for="published_at"&gt;published_at&lt;/label&gt;
                  &lt;input type="date" class="form-control" id="published_at" name="published_at" value="{{old('published_at')}}" placeholder="published_at"&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;label for="published_at"&gt;انتخاب تصویر&lt;/label&gt;
                  &lt;input type="file" name="file" id="file"&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;label for="category_id"&gt;CATEGORY ID&lt;/label&gt;
                  &lt;select name="category_id[]" class="form-control" multiple&gt;
                      @foreach($categories as $category)
                          &lt;option value="{{$category-&gt;id}}"&gt;
                              {{$category-&gt;name}}
                          &lt;/option&gt;
                      @endforeach
                  &lt;/select&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="author_id"&gt; Author&lt;/label&gt;
                  &lt;select name="author_id[]" class="form-control" multiple&gt;
                      @foreach($authors as $author)
                          &lt;option value="{{$author-&gt;id}}"&gt;
                              {{$author-&gt;name}}
                          &lt;/option&gt;
                      @endforeach
                  &lt;/select&gt;
              &lt;/div&gt;
  
              @if ($errors-&gt;any())
                  &lt;div class="alert alert-danger"&gt;
                      &lt;ul&gt;
                          @foreach ($errors-&gt;all() as $error)
                              &lt;li&gt;{{ $error }}&lt;/li&gt;
                          @endforeach
                      &lt;/ul&gt;
                  &lt;/div&gt;
              @endif
              &lt;button type="submit" class="btn btn-success"&gt;Submit&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
  @endsection</code></pre>
  </div>
  </div>
  </p>
  
  <p>and it's my Controller:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\author;
  use App\book;
  use App\category;
  use App\File;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\App;
  use Illuminate\Support\Facades\Auth;
  use Illuminate\Support\Facades\DB;
  use Illuminate\Support\Facades\Input;
  use Illuminate\Support\Facades\Storage;
  
  class BookController extends Controller
  {
      public $book;
      public $file;
      /**
      public function __construct()
      {
          $this-&gt;middleware('auth')-&gt;only('create');
      }
  */
      public function index()
      {
          $books = Book::with(['user'])-&gt;get();
          return view('books.index', compact('books'));
  
      }
  
  
      public function show($id)
      {
          $book = Book::with('categories','authors')-&gt;find($id);
          return view('books.show', compact('book'));
      }
  
  
      public function create()
      {
          $categories = Category::all();
          $authors = Author::all();
          $files= File::all();
          return view('books.create', compact('categories','authors','files'));
      }
      public function store(Request $request)
      {
          $this-&gt;validate($request,
              [
                  'name'=&gt;'required|string|max:256',
                  'pages'=&gt;'required|integer|numeric',
                  'ISBN'=&gt;'required|string|numeric',
                  'price'=&gt;'required|integer|numeric',
                  'published_at'=&gt;'required|date|date',
                  'file'=&gt;'required',
  
              ]
          );
  
  
          if ($request-&gt;hasFile('file')) {
              $filename = $request-&gt;file('file')-&gt;getClientOriginalName();
              $request-&gt;file-&gt;storeAs('public', $filename);
              $file = new File;
              $file-&gt;name = $filename;
  
              $file-&gt;save();
  
          }
  
          $book =  Auth::User()-&gt;books()-&gt;create($request-&gt;except('_token'));
          $book-&gt;categories()-&gt;attach($request-&gt;get('category_id'));
          $book-&gt;authors()-&gt;attach($request-&gt;get('author_id'));
          $book-&gt;files()-&gt;attach($request-&gt;get('book_id'));
          return redirect('/books');
      }
  
  }
  
  
  its web.php:
  
  &lt;!-- begin snippet: js hide: false console: true babel: false --&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and it's index.blade.php where we can see fields in browser:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@extends('layouts.app')
  @section('content')
  
  
      &lt;div class="container"&gt;
          &lt;table class="table"&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      Book Name
                  &lt;/th&gt;
  
                  &lt;th&gt;
                      Creator
                  &lt;/th&gt;
              &lt;/tr&gt;
  
              @foreach($books as $book)
                  &lt;tr&gt;
                      &lt;td&gt;&lt;a href={{"/books/".$book-&gt;id}}&gt;{{$book-&gt;name}}&lt;/a&gt;&lt;/td&gt;
                      &lt;td&gt;{{$book-&gt;user-&gt;name}}&lt;/td&gt;
                      @can('update',$book)
                          &lt;td&gt;&lt;a href="{{Route('books.edit',['id'=&gt;$book-&gt;id])}}" class="btn btn-primary"&gt;edit&lt;/a&gt;&lt;/td&gt;
  
                          &lt;!-- Button trigger modal --&gt;
                   &lt;td&gt;      &lt;button type="button" class="btn btn-danger" data-toggle="modal" data-target="#exampleModal"&gt;
                             delete
                          &lt;/button&gt;
                   &lt;/td&gt;
  
                    
                      @else
                          &lt;td&gt;
  
                          &lt;/td&gt;
                      @endcan
  
                      &lt;td&gt;
  
                      &lt;/td&gt;
  
                  &lt;/tr&gt;
  
              @endforeach
          &lt;/table&gt;
  
          &lt;div class="mt-3"&gt;&lt;/div&gt;
          &lt;a href="{{'/books/create'}}" class="btn btn-success btn-block"&gt;Create&lt;/a&gt;
  
      &lt;/div&gt;
  
  
  @endsection</code></pre>
  </div>
  </div>
  </p>
  
  <p>all of my code run right but my question is that how can I do to display image file to browser?  I mean ;how can use img tag in index.blade.php to that image displays in browser?
  (I didn't write all of my code because it would be too long and I just want a short code in img tag,something like this: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>'&lt;img  src="public/' . $file-&gt;getClientOriginalName() .'"  /&gt;';</code></pre>
  </div>
  </div>
  </p>
  
  <p>but you know it dosen't work in blade.What can I do?</p>