2016-05-15 84 views
3

我已经搜索了关于我的问题,我找到了一些解决方案,但这些都没有解决我的问题。我使用laravel 5.2,在这里我想上传一个图像,并在视图中显示它。我可以上传任何图像, 。但两件事情是:如何在Laravel刀片模板中显示上传的图像?

  1. 我看到,在数据库profilePic coloumn是null。但图像 完全在我的公共/ IMG文件夹上传。
  2. 而我如何显示它的视图?

ProfileController可的存储数据是这样的:

$file = array('profilePic' => Input::file('profilePic')); 

$destinationPath = 'img/'; // upload path 
$extension = Input::file('profilePic')->getClientOriginalExtension(); 
$fileName = rand(11111,99999).'.'.$extension; // renaming image 
Input::file('profilePic')->move($destinationPath, $fileName); 

Profile::create($profile); 

而且我的资料片是这样的:

@foreach($profiles as $profile) 
    <tr> 
     <td> <img src='{{ asset($profile->profilePic) }}'> </td> 
    </tr> 
@endforeach 

哪里是我的代码的问题?请帮助。我是Laravel的初学者。 在此先感谢。

回答

3

你引用的资产文件夹中{{ asset($profile->profilePic) }}

您就可以开始注释掉foreach循环与src='img/FILENAME.EXTENSION'更换src='{{ asset($profile->profilePic) }}'你应该看到您上传的个人资料PIC在视图中的IMG文件夹。

数据库中的profilePic列为空,因为您没有使用配置文件图片路径更新数据库。您为控制器发布的代码仅将上传的图像保存在目标img文件夹中,但不会发生数据库更新。