LARAVEL 8 - I cannot view images from the Storage folder - laravel

sorry but I would need help with a project and I would be really grateful if you would help me.
The problem is that i cannot view the images from public/storage in a blade page.
To display the images I wrote:
<img class="card-img-top" src="{{ asset('storage/images/' . $category->image) }}" alt="">
To create the folder public/storage I used the command:
php artisan storage:link
I tried to delete and to recreate the folder but it still doesn't work
The path of images:
storage/app/public/images/
I'm so sorry for my english, I hope you understand the problem.

If you are a Linux user, then sometimes you need to give permission additionally to make it accessible. If you create your storage folder by the command php artisan storage:link and the storage folder has been corrupted, then delete the generated folder from public on the root and generate the shortcut by running the command again. Hopefully it will work.

Related

Cannot find declaration to go to for assets

Most of my assets of my Laravel project are either in /storage folder or in the /public folder.
In my blade files, I references these asses with url('/storage/..). PhpStorm thinks that those do not exists.
When I commit, each image will add up to one error.
How can I tell PhpStorm that my assets are indeed in this directory?
I tried to add storage folder to PHP>Laravel>Views/Template but this doesn't work and I believe I have not fully understood what this path/namespace blade thing is supposed to do.
You could use the asset helper
style="background-image: url('{{ asset('storage/backgrounds/lavender') }}');">dfsdf</div>
do command this
php artisan storage:link
will create shortcut folder in public/storage to path storage/app/public
ineasted of url('/storage/..) to public_path('storage/....')

Cannot display image in vue.js

I'm saving image in following path :
storage\app\public\img\user_image
and saving image url like this in database:
/img/user_image/285070719.png
trying to display image like this:
<img :src="'../app/public'+profile.image">
but the image does not display, Any solution to resolve this issue is highly appreciated.
Have you create a storage link? php artisan storage:link https://laravel.com/docs/8.x/filesystem#the-public-disk
Then you should be able to use the uri like /storgae/img/user_image/285070719.png
Make sure that you created the symlink from public/storage to storage/app/public with php artisan storage:link, after that make sure that the generated URL is correct.
The following URL should be generated:
http://localhost:8000/storage/img/user_image/285070719.png
Something like the following should work for you:
<img :src="'/storage'+profile.image">
From the docs:
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. To create the symbolic link, you may use the storage:link Artisan command: php artisan storage:link

how do i solve the image upload issue of laravel while hosting it on shared hosting?

i am using hostinger to deploy my laravel project i uploaded all the files into the public_html folder and then did all the necessary changes needed for the application to work.The app seems to work pretty fine but when an user tries to upload a image the image gets stored in the storage/app/public/avatar folder and on public/storage/avatar folder as i have used symlink to link the two folders but yet the photos cannot be viewed by the users. this is how i recall my photo
div class="profile-avatar" style="width: 400px;height:500px; border-radius: 0%;background-image: url('#if(Auth::user()->avatar == "avatar.png") {{ url("/imgs/".Auth::user()->avatar) }} #else {{ url("/storage/avatar/".Auth::user()->avatar) }} #endif');"
please help me to solve this issue
As you have no ssh access to run some command in shell,
try this when uploading the image
1. Store image here: public_path() . 'img/filename.jpg'*
2. Save the 'img/filename.jpg' in database
3. Generate the image URL with url('img/filename.jpg')
// Output http://www.your-domain.com/img/filename.jpg
If you can manage shell access then try this:
Remove your current app/public/avatar directory, which is created inside of storage folder.
Also remove your storage folder inside public !
After that via ssh cli, cd to your laravel project folder and create a symbolic link via following command
ln -sr storage public/storage
Hopefully it will solve your issue. I had same issue and mine got fixed via second method ( I had ssh access to my server ).

Not Showing user avatar

HTML tag
<img src="storage/app/avatars/23_avatar1548246815.bmp" alt="">
File already exist on this path. But not showing.
And I used also this php artisan storage:link, but not working.
Error is Server Error 403 Forbidden.
According to laravel documentation.
The Public Disk
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.
To create the symbolic link, you may use the storage:link Artisan command:
php artisan storage:link
Of course, once a file has been stored and the symbolic link has been created, you can create a URL to the files using the asset helper:
echo asset('storage/file.txt');
thing I would do is definitely use this method
<img src="{{asset('assets/images/image.png')}}">
to link to your asset files.
Shouldnt the storage/app/avatars be storage/app/pubic/avatars ?
If you say that the file exists on that path, it points that the problem is with file permissions. Change the /project/storage permissions to 777, delete the public/storage folder, and run php artisan storage:link, then try one more time. If no, try to give 777 permissions to public folder

Laravel Symbolic Link not working

I have some problems creating a symbolic link with laravel to access files that are in my storage
I am storing my files in
storage\app\public
I used the php artisan command to create the link
php artisan storage: link
The [public/storage] directory has been linked.
Earlier files were storing in storage\app\public and were also visible in public\storage folder
But now they are only storing in storage\app\public and not visible in public\storage folder
I am using link to show file path
{{ Storage::url($package->reportPath['path']) }}
Path is showing correct but it redirect to 404 page as there is no file I guess.
This solved it for me on laravel 8, hosted on a ec2 server.
rm public/storage
php artisan optimize:clear
php artisan storage:link
Try removing your public/storage directory and try running storage:link again. This worked for me.
If you are trying to Show the stored file use asset()
asset('storage/further_path/').$file_name;
To store file you can do
$destinationPath = storage_path('app/public/further_path');
if (!is_dir($destinationPath)) {
mkdir($destinationPath, 0777, TRUE);
}
$request->file->move($destinationPath,$filename);
Hope this Helps You.
Let me Know if You have any problem.

Resources