if i put an image in "storage/app/public/img/logo.png" and execute:
$ php artisan storage:link
How i get that logo.png in vue component?
<img src="storage/app/public/img/logo.png">
The requested it's ok (200) but that image not render, because is an SPA.
Thank you,
Well, after to do:
$ php artisan storage:link
In my component i used:
<img :src="'../storage/img/logo.png'">
thanks,
When you use the storage:link command, you create a symbolic link between your storage/app/public folder and your public/storage folder.
So now you can find your files at the url $BASE_URL/storage/img/logo.png.
I recommend you to use the asset helper function inside your blade template:
<img src="{{ asset('storage/img/logo.png' }}">
NOTE: be sure to set the proper file permissions on the folder or you get an Unauthorized error when trying to access it.
Check config/filesystems.php (ie: unmodified default):
// If server doesn't support "making symbolic links":
// https://medium.com/#shafiya.ariff23/how-to-store-uploaded-images-in-public-folder-in-laravel-5-8-and-display-them-on-shared-hosting-e31c7f37a737
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Save an image:
$image = $request->file('image'); // something like that
$slug = 'some-slug-99';
$image->storeAs(
'examples' .'/'. $slug,
$image->getClientOriginalName(),
'public'
);
Create the symlink from /storage/app/public to public/storage (ie: your public html folder which makes asset() work in Laravel Blade templates, I think but don't quote me on that)
$ php artisan storage:link
Place the HTML in your Vue component:
<img
v-for="image in example.images"
:key="image.filename"
:src="`/storage/examples/${example.slug}/${image.filename}`"
>
Also, read the docs: https://laravel.com/docs/8.x/filesystem
When using php artisan storage:link you are creating a simbolic link from public/storage to storage/app/public
I'm used to use asset instead regular path: Try using src="{{ asset('storage/app/public/img/logo.png') }}
It is supposed that if you are using a SPA, when a component renders, it will make a new request to get the img
Hope my answer will help someone,
Create a symbolic link by using this command
php artisan storage:link
now use it in you vue template as following
/storage/path/to/file
routes/web.php
For SPA application, Laravel usually render index blade for all incoming requests.
Route::get('/{any}', function () {
return view('index');
})->where('any', '.*');
I changed this route so that all routes except "/storage/**/." locate index blade page.
This way, you can both render SPA and get uploaded image.
Route::any('{all}', function () {
return view('index');
})->where('all', '^(?!storage).*$');
I assume you have already created symlink using php artisan storage:link command.
Take a look Vue js laravel 8 routing
I don't know why no one write their solution clear.
In Laravel and vuejs
When you store files inside laravel storage do as bellow;
create a symlink by running php artisan storage:link it will create a directory inside your-project/public by the name of storage which is not actually a directory that is a link to project/storage directory, if you navigate to your-project/public you will see all the files uploaded into your storage showing here, now you cannot access your file directly from here.
If you have an image stored in this location: storage/app/public/files/logo.png the path to show the image in vue a component will be /storage/files/logo.png please escape app/public parts.
<b-avatar href="#" :src="'/storage/files/logo.png'"></b-avatar>
I hop it help someone.
Related
I have done php artisan storage:link.
So in .vue page the image can't be found by path: :src="'/./storage/'+question.image".
My 404:
The image is uploaded in db:
And stored in storage/app/qImagess:
Structure of public folder:
Could anyone help me, please?
add this to config/filesystems.php in:
'links' => [
...
public_path('qImagess') => storage_path('app/qImagess'),
],
then
php config:clear
php artisan storage:link
the link should be:
127.0.0.1:8000/qImagess/1385873137.png
so add it to vue as:
:src="'/'+question.image"
Here is the Docs for that: https://laravel.com/docs/9.x/filesystem#the-public-disk
Thanks to the help of sir #AhmedAlQahtani, it is done after all.
The problem was in linking:
'links' => [
...
public_path('qImagess') => storage_path('app/qImagess'),
],
This had to be outside of drivers in filesystems.php. That's why php artisan storage:link didn't do the job.
Here is public folder, where created proper qImagess folder is with uploaded images.
I was using laravel by the project URL without using serve and i didn't have this kind of problems.
But now i'm using it, so i thought that this is the reason.
I've got a problem to display the images from storage path, i tried some stuff like run the storage link PHP artisan storage:link and get the path using storage_path('app/' . $filename) but it didn't work
Your are not providing correct path to the storage_path helper your storage_path('app/' . $filename) is not working because you have not put / before app try putting a slash before app like storage_path('/app/' . $filename)
also
if you want to get the file in blade then you can use url helper like {{ url('storage/app/'.$filename) }}
I have an add-on-domain as public_html/xyz.in. I am uploading images and images are getting stored inside storage/app/public/images folder. However when I am trying to fetch images from that folder, its showing 404 not found. Please help.
<img src="{{ asset('storage/app/public/images/tulips.jpg') }}">
The folder storage is not available to visitors. That's why you need to create a symbolic link from the public directory.
You can use artisan, to get a symbolic link
php artisan storage:link
You need to create a symbolic link of your storage folder. i.e storage/app/public to public/storage. if you have SSH access you can use php artisan storage:link as #wschopohl suggested. Else you can create a php script to create that symlink.
<?php
$target = '/home/user/domain/storage/app/public';
$shortcut = '/home/user/domain/storage';
symlink($target, $shortcut);
?>
After running you can see storage folder in your public folder. Now you can access image with <img src="{{ asset('storage/folder_name/image_name.jpg') }}">
You can create a storage link. run bellow command :
php artisan storage:link
And display:
<img src="{{ asset('public/storage/templates/image.png') }}" class="img img-thumbnail">
Read a full post: How to display the storage folder image in Laravel
I have some problems creating a symbolic link with laravel to access some images that are in my storage ...
I store my images in the folder
storage\app\public\clients
where I have images 1.png, 2.png and so on ...
I used the php artisan command to create the link
php artisan storage: link
The [public/storage] directory has been linked.
now when i try to access in my view the following path does not work
<img id = "thumbnail" src = "{{asset ('clients / 1.png')}}" width = "150px"> </ img>
do I have to do anything else to gain access to the storage folder in public?
This command will create a link between public/storage and storage/app/public.
So, change this:
{{ asset('clients/1.png') }}
To:
{{ asset('storage/clients/1.png') }}
https://laravel.com/docs/5.5/filesystem#the-public-disk
In my Laravel project I'm trying to load an image into my view using blade but it displays as a broken link. I inspect it with firebug and the src is pointing to the image but nothing is displaying.
My image is located in my project's public/images/users/3/profilePictures/
Here is my <img> in the view.blade.php
<img class="com-profile-picture" src="images/users/{{ $follower->id }}/profilePictures/50thumb-{{ $follower->profilePicture->url }}" alt="{{ $follower->first_name }} {{ $follower->last_name }} Profile" width="50" height="50">
However I get this when I load the page:
When I inspect the image with firebug I see this:
That is the correct src and the image does exist in my public/images/users/3/profilePictures/ directory
Anyone know why this is happening?
This may be caused you are in a route which does not represent the base URL. You should generate the URL for your assets relative to the public/ folder. Use URL::asset('path/to/asset') to generate the URL.
{{ URL::asset("images/users/{$follower->id}/profilePictures/50thumb-{$follower->profilePicture->url}") }}
Or as #lukasgeiter mentioned you can simply use asset('path/to/asset') helper.
You can try with the
php artisan storage:link
else you can use this
A simple fix for the issue (linked broken error)
in .env file
APP_URL=http://localhost
this replace with the
APP_URL=http://localhost:8000
then the issue will be fixed.
delete already generated symlink and then run this command
php artisan storage:link
if you are using laravel, consider excluding public folder or any folder where your public files are store in .htacccess from folders that laravel control.
Do it like this in .htaccess
# Exclude directory from rewriting RewriteRule ^(public/) - [L]
Storage location before (Not Working) :
<img src="{{asset('storage/app/public/media/productImages/'.$list->image)}}" alt="" srcset="">
Working storage location :
<img src="{{asset('storage/media/productImages/'.$list->image)}}" alt="" srcset="">
Else try :
Deleting all the linked/shortcut folders created in public folder
Then recreating the link by running :
php artisan storage:link