How to display images from storage path using artisan serve - laravel

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) }}

Related

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

Laravel 5.5 image storage asset() helper config

I have images in storage/app/ trying to access them with {{asset('about.jpg')}}. The path that is returned == test.com/about.jpg but the image resides in test.com/storage/about.jpg. Should I change the {{asset('storage/about.jpg')}} or is there a filesystem issue I am not seeing? TY
As per laravel doc try linking your directory by using php artisan storage:link
and then you can access your file like {{asset('about.jpg')}}

How to access settings from `.env` inside the `index.php`

I’m creating a deployment configuration for Laravel project.
On my hosting public/ folder must be moved to another place.
Obviously, since that, I need to change path to the autoload.php and app.php in index.php.
However, I’d like to add and use a parameter which would tell where these files reside. Something like this:
require __DIR__ . '/../' . env('DEP_EXT_FOLDER') . 'vendor/autoload.php';
I think, the most proper place for such a parameter is .env file.
However, I’ve got an error:
Call to undefined function env()
You can't use the env() function before loading the autoloader.
if you absolutely want to use your .env file, you will have to use native php preg_match() for finding your key and using the value after that :)

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

Laravel assets url

I have installed Laravel and began trying to write an app. I made some directories for my assets in the same directory as /app. But when I try to visit an image in my localhost for example: http://localhost/assets/images/image.png
I've also tried it on: http://localhost/app/assets/images/image.png
I ran into the problem when I was trying to set a background image in a view, and it kept going to 404.
This is what my app looks like under app/
->app
->assets
->commands
->config
->controllers
->database
->lang
->models
->start
->storage
->tests
->views
app.txt
routes.php
filters.php
But I get errors about requests. I have double checked that the url is correct.
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
You have to put all your assets in app/public folder, and to access them from your views you can use asset() helper method.
Ex. you can retrieve assets/images/image.png in your view as following:
<img src="{{asset('assets/images/image.png')}}">
You have to do two steps:
Put all your files (css,js,html code, etc.) into the public folder.
Use url({{ URL::asset('images/slides/2.jpg') }}) where images/slides/2.jpg is path of your content.
Similarly you can call js, css etc.
Besides put all your assets in the public folder, you can use the HTML::image() Method, and only needs an argument which is the path to the image, relative on the public folder, as well:
{{ HTML::image('imgs/picture.jpg') }}
Which generates the follow HTML code:
<img src="http://localhost:8000/imgs/picture.jpg">
The link to other elements of HTML::image() Method: http://laravel-recipes.com/recipes/185/generating-an-html-image-element
{{ asset('js/jquery.min.js') }}
//Full Path http://127.0.0.1:8000/images/slides/2.jpg
Do Not Add Public folder name

Resources