Chonchol Mahmud
Chonchol Mahmud

Reputation: 2735

How to show uploaded image in Laravel blade template?

I have searched about my problem and i have found some solution but those are not solve my problem.I am using laravel 5.2 and here i want to upload an image and show it in view.I can upload any image and it works well.But two things is:

  1. I see that in database profilePic coloumn is null.But images are perfectly uploaded in my public/img folder.
  2. And How can i show it in view?

My ProfileController's store data like this:

$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);

And my profile blade like this:

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

Where is the problem in my code? Please help.I am beginner in Laravel. Thanks in Advance.

Upvotes: 4

Views: 3820

Answers (2)

Diksha Yadav
Diksha Yadav

Reputation: 1

In view file , you can show it using src="{{asset('storage/'.$post->image)}}" , if you have linked the storage folder from local to public using php artisan storage:link .

Upvotes: 0

Stephen Mudere
Stephen Mudere

Reputation: 454

You are referencing to the assets folder by {{ asset($profile->profilePic) }}

you may start by commenting out foreach loop and replacing src='{{ asset($profile->profilePic) }}' with src='img/FILENAME.EXTENSION' you should see your uploaded profile pic in the img folder on the view.

The profilePic column in the database is blank as you are not updating the Database with the profile pic path. The code you posted for the controller only saves the uploaded image in the target img folder but there is no database update taking place.

Upvotes: 3

Related Questions