Laravel Displaying image from database

后端 未结 6 1912
小鲜肉
小鲜肉 2020-12-20 06:49

so i wanted to display the image not the image name in my views.

i got this in my views

image}}\" />

相关标签:
6条回答
  • 2020-12-20 07:00

    The image was saved to the database, but you don't know which folder on disk the image was saved to, so look on your controller to see where it is saved.

    Then in blade you can use:

    <img src="/folder_name_path/{{$post ->image}}" />
    
    0 讨论(0)
  • 2020-12-20 07:07

    style="url(background-image:images/bg.jpg) how to fetch image in this case

    0 讨论(0)
  • 2020-12-20 07:08

    You can use like this <img src="{{ asset('img')}}/{{ $post->image) }}" />

    Your image directory is public/img/image's name

    0 讨论(0)
  • 2020-12-20 07:10

    if your image is in public/images folder use below.otherwise use the path in project for that image in the public folder.concatenate with the image extension.

    <img src="images/{{$post->image}}.jpg" alt={{$post->image}}/>

    0 讨论(0)
  • 2020-12-20 07:14

    First, you have to store the images in the public directory (if not the browser can't access them)

    Then it depends what $post->image actually is. If it is a path relative to public you can do this:

    <img src="{{ asset($post->image) }}" />
    

    Or:

    {{ HTML::image($post->image, '', array('class' => 'image')); }}
    

    Edit

    Since you're images are stored in public/img and the image attribute only holds the name (without img/) you have to prepend that:

    <img src="{{ asset('img/' . $post->image) }}" />
    
    0 讨论(0)
  • 2020-12-20 07:19
    1. Insert Your Image:

      public function store(Request $request)
       {
       $pages = new Appsetting();
      
              $pages->title = $request->input('title');
              $pages->description = $request->input('description');
      
              if ($request->hasfile('image')) {
                  $file = $request->file('image');
                  $extension = $file->getClientOriginalExtension(); // getting image extension
                  $filename = time() . '.' . $extension;
                  $file->move('uploads/appsetting/', $filename);
      
      //see above line.. path is set.(uploads/appsetting/..)->which goes to public->then create
      //a folder->upload and appsetting, and it wil store the images in your file.
      
                  $pages->image = $filename;
              } else {
                  return $request;
                  $pages->image = '';
              }
             $pages->save();
      
             return redirect('pagesurl')->with('success', 'App Setting Added');
       }
      
    2. Display it by index

       public function index()
          {
              $pages = Appsetting::all();
              return view('admin.appsettings.pages', compact('pages',$pages));
          }
      
    3. Come to Blade file. (pages.blade.php)

      @foreach ($pages as $page)
      <td> <img src="{{ asset('uploads/appsetting/' . $page->image) }}" /> </td>
      @endforeach
      
    4. set your route and 100% working.

    0 讨论(0)
提交回复
热议问题