Mihai
Mihai

Reputation: 26784

Display image in laravel 7

I store an image with

$cat->picture = $request->file('catpicture')->store('public/catpictures');
$cat->save();

I do a ls in "/var/www/html/project/storage/app/public/catpictures", the image is saved

I created the symlink

php artisan storage:link
The [/var/www/html/project/public/storage] link has been connected to [/var/www/html/project/storage/app/public].
The links have been created.

In my blade I have:

<img src="{{url($cat->picture)}}" class="img-thumbnail" alt="Responsive image">

which is "public/catpictures/IgTx81OYKVymthuzTydFVepGvFZGALeeW1FmHpas.png"

The image doesnt show,what am I missing? The src is http://127.0.0.1:8000/public/catpictures/IgTx81OYKVymthuzTydFVepGvFZGALeeW1FmHpas.png

Upvotes: 1

Views: 6918

Answers (1)

Jems
Jems

Reputation: 1706

Instead of using url, better to use asset to retrieve asset

Actually you don't need to add public prefix in your store() function. When you call store(), it will use the path from config/filesystems.php. The path will be taken from the default disks.

Asset vs Url

<img src="{{asset('/storage/' . $cat->picture)}}" class="img-thumbnail" alt="Responsive image">

Upvotes: 1

Related Questions