After Upgrading Wamp Images in Storage Not Showing 404 not found - laravel

I am facing a weird problem I am recently upgraded wamp server , but i find out that image dosn't load as it was before upgrading , when I open the image URL in the browser it showing error 404 : page not found
here is my code :
<img src="{{ asset('storage/profile_pics/'.$user->profile_pic) }}" class="img-responsive" alt=""> </div>
any help ?

in your .env file add your APP_URL = to your root folder url which u use to get to your laravel app through WAMP server.
if it doesn't work
You can configure the asset URL host by setting the ASSET_URL variable in your .env file. This can be useful if you host your assets on an external service like Amazon S3:
// ASSET_URL=http://example.com/assets
$url = asset('img/photo.jpg'); // http://example.com/assets/img/photo.jpg
according to this:-
https://laravel.com/docs/5.7/helpers#method-asset
P.S: if you use the command
php artisan serve
and update your APP_URL in your .env file to localhost:8000 , it will work just fine.

Related

Images not showing up in laravel

So I have images working on my dev environment, however when i try to see them on the production server I receive a 404 error, the images are located in storage/app/public folder, I have ran the following command:
php artisan storage:link
The output says it works however it is still a 404 error when navigating to /storage/imagefolder/image on the site
Technically images are accessible through the public folder, not the storage folder.
In your Code you can access them like:
<img src="{{ asset('imagefolder/image') }}" />
You can find the correct/final image url with:
dd(asset('imagefolder/image'));
First delete the old symlink
Then from the command:
php artisan storage: link
And to display files: ‌
<img src="{{ asset('imagefolder/fileName') }}" />
or
<img src="{{ /storage/imagefolder/fileName }}" />
File permission error on the existing link to storage from the public folder, deleting the link and re running the command fixed the issue.

Laravel storage path isn't accesisble. How to access it from url?

In a laravel I currently have a file saving to the storage directory.
The file appears here
"myroot/storage/app/public/attribute_item/3pCPNl7XaJpIsryhRuVYPdqNp4rKknU737mQ3bGz.svg"
I can visually confirm it's there.
I then attempt to load this up with the following url which is stored in my db:
<img src="{{ asset('storage/app/public/'. $item->image_path) }}" height="50" width="50" onClick="selectImage(this)" style="cursor: pointer;"/>
This gives me a 404 that it doesn't exist. The request url it's attempting to get is this:
http://127.0.0.1:8000/storage/app/public/attribute_item/3pCPNl7XaJpIsryhRuVYPdqNp4rKknU737mQ3bGz.svg
What am I missing here? Is there a specific way I have to call a storage asset?
I was missing this part: php artisan storage:link
This creates the symlink so it will be viewable publicly.
More info found here:
laravel.com/docs/8.x/filesystem#the-public-disk

Asset Helper Function Not Working Correctly in Laravel 5.7

I'm new to MVC and Laravel, and I'm trying to include CSS but getting a 404 error. The URL it's generating is...
http://localhost/testing_laravel/css/app.css
If I use the URL this way instead...
http://localhost/testing_laravel/public/css/app.css
It works fine.
My question is why do the tutorials and documentation not use '/public'? Is there something I am not aware of? Please guide me on how I should use URLs for assets.
{{ asset('css/app.css') }}
The asset() helper prepends the base URL (http://localhost/testing_laravel) to the given path 'css/app.css'. Within the Laravel directory structure, these assets live in the /public folder and Laravel knows that.
When you create your virtual host for your Laravel install you need to make the /public directory the root. Or, try php artisan serve.
You are missing the port http://localhost:8000/testing_laravel/css/app.css
Just open command line & point to root of your project, Then run php artisan serve.
This is the proper way.
{{ asset('css/app.css') }} will point to the public directory

missing images and home page when moving laravel 5.2 project to live server

images works fine in localhost as src="/lr/public/bootstrap/images/photo.jpg"
but don't work on live server
error messages on live server is failed 404 not found www.mysite.com/lr/public/bootstrap/images/photo.com
note : when i remove /lr/public images works on live server
my cpanel root directory is /home/ad
in /home/ad >>
i have folder'lr' that containe my project and i deleted folder public in it
in public_html >>
i have contents of folder public >> bootstrap - uploads - index.php ..... etc
Looks like you didn't link your images correctly.
I believe the link should be:
www.mysite.com/bootstrap/images/photo.jpg
not:
www.mysite.com/lr/public/bootstrap/images/photo.com
Use: asset('bootstrap/images/photo.jpg') for linking files from your public folder.
Blade example. <img src="{{ asset('bootstrap/images/photo.jpg') }}">
Make sure 'photo.jpg' exists in 'public/bootstrap/images/' directory

Image not displaying in view. Laravel

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

Resources