图像未在Laravel 5.2中显示为预期

时间:2016-06-09 13:23:51

标签: php laravel laravel-5.2 laravel-blade

我有一个表单,用户可以在其中输入详细信息及其图像。我编写的代码可以获取图像并将其存储在名为' image'的列中。作为bin文件,列的数据类型是blob。但是,当我尝试在视图中显示图像时,图像不会显示。

控制器

<?php

public function showProfile($username)
{
    $user_details = User::get()->where('name', $username);
    return view('profile-page', ['user_details' => $user_details]);
}

查看

<div class="panel-body">
    <form class="form-horizontal" role="form" method="POST" action="{{ url('/user-post') }}">
        {{ csrf_field() }}
        <input type='hidden' value='{{Session::token()}}' name="_token">
        @foreach($user_details as $user)
            <img src="data:image/jpeg;base64,'.base64_encode( {{$user->image}} ).'"/>
            <p>
            <h2>
                <center>hello This is {{$user->name}} </center>
            </h2>
            <h2>
                <center>I am a {{$user->nationality}} </center>
            </h2>
            <h2>
                <center>This great person was born on {{$user->dobday}}-{{$user->dobmonth}}-{{$user->dobyear}} </center>
            </h2>
            <h2>
                <center>Contact me here {{$user->email}} </center>
            </h2>
        @endforeach
    </form>
</div>

除了图像之外,所有细节都按预期显示,这里的问题是什么?

1 个答案:

答案 0 :(得分:0)

你在这里弄错了:

base64_encode( {{$user->image}}

尝试这样:

{{ base64_encode($user->image) }}