0

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.

4
  • 1
    What's the content of Auth::user()->image ? Commented May 15, 2019 at 9:17
  • did you use blob file type in your image column ? Commented May 15, 2019 at 9:17
  • @frogeyedman Yes I do : Commented May 15, 2019 at 9:19
  • @cbaconnier Its an image that I upload on a form Commented May 15, 2019 at 9:20

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

12 Comments

I don't know if it change something but its "longblob" not "blob"
To clarify: blob can only store as much as 16 KB of data. mediumblob up to 64 MB and longblob with 4 GB nearly the whole internet.
@Dan thanks for the clarification ahah, so even with base64 encoder I still have this problem
If you've used blob before and changed it so it can hold larger images, you might have to upload the image again.
@Dan Nah I stille used longblob and nothing change :/
|
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.