0

I am trying to add and display a image from mysql database stored in BLOB type in my web App, but while using {{ Auth::user()->profile_pic }} getting errors, can someone tell me what mistake i am doing and how to do this using laravel 5.

dashboard.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-3">
            <div class="panel panel-default">
              <div class="panel-heading">Profile</div>
              <div class="panel-body">
                <img src="{{ Auth::user()->profile_pic }}" class="img-circle" width="200" height="200">
                <h3>{{ Auth::user()->name }}</h3>
                <h5>{{ Auth::user()->email }}</h5>
                <hr>
                <h6>{{ Auth::user()->created_at }}</h6>
              </div>
            </div>
        </div>
        <div class="col-md-9">

        </div>
    </div>
</div>
@endsection

Jatin Balodhi
  • 152
  • 5
  • 18
  • http://stackoverflow.com/questions/7793009/how-to-retrieve-images-from-mysql-database-and-display-in-an-html-tag " take help from this question" – Sushant Yadav Apr 20 '16 at 18:37

1 Answers1

0

The html <img src="{{ Auth::user()->profile_pic }}" class="img-circle" width="200" height="200"> needs address url instead of {{ Auth::user()->profile_pic }} Add code in route first get the address using response object

Route::get('/' function($user) {
    $Image = Auth::user()->profile_pic;
    return response($Image)->header('Content-Type', 'image/jpeg');
}

then now pass address of response to the html element

Route::get('/dashboard', function() {
    $id = Auth::user()->id;
    $Image_url = "user/$id/profile-pic";
    return view('/dashboard', ['Image_url' => $Image_url]);
}

Passing address in blade

<img src="{{ $Image_url }}" class="img-circle" width="200" height="200">
smartrahat
  • 5,381
  • 6
  • 47
  • 68
Jatin Balodhi
  • 152
  • 5
  • 18
  • I would certainly take this logic out of the routes file and create a ViewComposerServiceProvider, etc. In boot, `view()->composer('route', function($view) { $view->with('image_url', **code**); });` etc. – Mike Barwick Apr 25 '16 at 18:52
  • Routes for this logic is ugly - and shouldn't be practiced, IMHO. – Mike Barwick Apr 25 '16 at 18:57