Bastien
Bastien

Reputation: 81

Laravel does not display uploaded image

I'll need your help there, I have a form when I submit an image, it's working fine, but when I try to display the image on an another page, its display a white square (I can see that it's working because I can see the name of the image in the console). This is my app.blade.php :

   <div class="menu_connect_big_screen">
                <img src="{{Auth::user()->image}}"/>
                <p>{{Auth::user()->firstName}} {{Auth::user()->lastName}}</p>
                <a href="{{ url('/my_account') }}">Mon compte</a> | <a href="{{ url('/logout') }}">Se déconnecter</a>
            </div>

And this is my controller :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use Auth;


class ProfilePictureController extends Controller
{
    public function update(Request $request)
    {
        $request = $request->All();

            User::where('id', Auth::user()->id)
                ->update(
                    [
                        'image' => $request['image']]
                );
            return redirect()->to('/')->with(['image-changed' => 'Photo de profil modifiée !']);
        }

}

I'm kinda new to laravel so any help would be thankful. Thank you.

Upvotes: 0

Views: 98

Answers (2)

Natvarsinh Parmar - bapu
Natvarsinh Parmar - bapu

Reputation: 1138

For example user images stored in public/user_images directory

   <div class="menu_connect_big_screen">

       <img src="{{ asset('user_images/' . Auth::user()->image) }}" height="50px" width="50px">

       <p>{{Auth::user()->firstName}} {{Auth::user()->lastName}}</p>
       <a href="{{ url('/my_account') }}">Mon compte</a> | <a href="{{ url('/logout') }}">Se déconnecter</a>
   </div>

Upvotes: 0

frogeyedman
frogeyedman

Reputation: 534

If the image is stored in blob you should use base64 in your image tag like so;

<img src="data:image/jpeg;base64,{{base64_encode( Auth::user()->image )}}"/>

However, this is not specific to Laravel.

Upvotes: 2

Related Questions