Laravel从数据库中检索图像

时间:2017-11-03 06:58:03

标签: php laravel-5

我需要在我的视图中显示存储的图像。我使用下面的代码在db中存储图像,

     $file = Input::file('pic');
     $img = Image::make($file);
     Response::make($img->encode('jpeg'));
     $picture = new Car;
    $picture->cartype = Input::get('cartype');
    $picture->price = Input::get('price');

    $FileName            = Input::file('pic')->getClientOriginalName();
    $FilePath = public_path('') .'/images/'. $FileName;
    $picture->name = $FilePath;
    $picture->save();

在我的控制器中(检索图像)

public function index()
{

            $cars = DB::table('car_category')->get();
           return view('category.category',['cars'=>$cars]);


} 

如何在视图中检索和显示图像?

1 个答案:

答案 0 :(得分:2)

如果要将图像名称存储在数据库中并将其上载到目录中,则只需从数据库中获取名称,然后返回名称进行查看并将名称附加到硬编码的目录地址即可轻松显示这个 -

<img src="/images/{{ $imageVariableName }}">

让我知道这是否有效。

相关问题