dont get the right path in laravel for my uploads folder - laravel

i always use this to go to the public folder:
src="{{ asset('img/pic.png') }}">
everything works perfect
but now is it not possible because i want to show the avatar picture and
something like this not works
<img src="../../public/uploads/avatars/{{$user->avatar}}">
so ive used this but it doesnt work i dont know how to go to the uploads folder
does anybody know the reason?
thank you!!!

Within the asset() helper, you have missed out the uploads/ folder.
So this should be src="{{ asset('uploads/avatars/' . $user->avatar) }}"

If your uploads folder is in the public folder, there is no need to use the asset() helper. You could just use the following:
<img src="/uploads/avatars/{{$user->avatar}}">

Related

Laravel Dompdf error 'Image not found or type unknown'

I have a problem to show image that is in public folder.
My PDF print is in not in blade, it is in helper folder. Can that be the issue? I attached below two images of my code.
According to this question you have to use the full server path try:
<img src="{{ public_path("storage/images/apple.png") }}" alt="" style="width: 150px; height: 150px;">
Note:
Image must save in the public folder only
please post you images here, not external links, how ever.
if you use a relative path to the images, the pdf loader don't know where load the file, so you have to use an absolute route, you can use the helper asset() to reference the public folder files
asset('images/raxca_logo.png')
also make sure in your .envfile you hace the correct url in the APP_URL variable

How do I display and image from database to laravel blade?

I have followed the correctly marked answer in this question to save images in my app. I am having trouble displaying the images to blade file. I am using <img src="{{asset('/ProfileImages'.$p->profile_image)}}" alt="..."> ProfileImages is the storage folder with structure storage/app/ProfileImages. How do I display the images as the above line doesnot display?
Laravel storage filesystem is so unique. When you doing any upload it will upload in the storage/app/public directory. To make it accessible in public directory, things need to do is create symlink by run command:
php artisan storage:link
Or
<img src="{{ Storage::url($p->profile_image) }} " alt=""/>
StorageDocumentation
use Storage::url()
<img src="{{ Storage::url($p->profile_image) }}" alt="...">
ref link https://laravel.com/docs/8.x/filesystem#file-urls
By default when using {{asset()}} this will look inside your Public directory you should either consider storing photos inside your Public directory
Or take a look at the documentation about Laravel File System, here they explain how you can use storage directory and link it with your public directory
Laravel File System
Aslo you can use {{Storage::url()}} instead

Asset not loading, css, js or even images are not loading or linking in my Laravel 7 project

I don't know how else to go about this issue. I've tried several suggestions I've seen online but to no avail. I'm working with laravel 7
My view is not loading any file from my public folder. Even images uploaded from the view to the directory is not loading back to view when called. I've symlink the storage and the public directory. However, I observed that my storage folder created was a shortcut but I expect that should be correct.
These are different ways I can remember I tried to call an image from the directory for example
<img src="{{ asset('storage/cover_images/img1.jpg') }}" alt="">
<img src="{{ URL::asset('storage/cover_images/img1.jpg') }}" alt="">
<img src="{{ Storage::url('cover_images/img1.jpg') }}" alt="">
<img src="/public/cover_images/img1.jpg">
Also note that all CDNs or images referenced externally are working properly.
When you symlink the storage public disc, a shortcut directory storage is created in your Laravel project's public folder. Now the asset() helper of Laravel isn't restricted to access storage files only, instead you can use this to access any file on the public path. By default, asset() helper uses the public directory as the root.
For example, if you have uploaded an image to public/images/first.png, then you can use asset('images/first.png') to generate the full URL for the image.
If you have properly symlinked the storage disk then you should be seeing files in the newly created public/storage directory. If it doesn't contain any files, you must have symlinked it improperly.
To ensure that asset() helper works fine, create a directory foo in your Laravel project's public folder and place some dummy file, i.e. test.png in that foo directory. Now using asset('foo/test.png'), you should be getting the full and valid URL to test.png file.
If it doesn't, maybe you have configured the asset helper's URL to some other destination using ASSET_URL in .env file.
I think you should not include storage or public , if you have symlink. You can call directly your asset like:
<img src="{{ asset('cover_images/img1.jpg') }}" alt="">

Can't load images in laravel blade files

I've downloaded a template from here.
I want to design pages like that in laravel blade pages, I put css and js files in public folder and link blade files to them, and it works.
But I can't handle images, there isn't a folder for images in this template and I don't know how to load them in my blade pages.
you can upload images on below path
storage/app/public/images
//this way you can use in your blade file
<img src = "{{ asset('/images/YOUR_IMAGE.png') }}" />
but you need to run one command
php artisan storage:link
it will create a symlink from public/storage to storage/app/public
please insert as below path and make link like that.
try this.
<div class="hidden-xs" style="width:200px; height:auto; margin-left:-10px;">
<img src="{{ asset('uploads/logos/myLogo.png') }}">
</div>
If not working... then check your App Url in /.env and restart your app server.
APP_URL=http://localhost
Happy coding~!:)

The requested URL /image.jpeg was not found on this server

I've got a Laravel in hosting company and I get this error:
The requested URL /image.jpeg was not found on this server.
This also happens with some CSS and JS files but not all the files. What could be? In my localhost environment everything works fine. Can it be some CPanel configuration that I'm missing?
Thank you :)
The standard way to do this is use asset() function. For example, I have example1.js file that I want to import/include/use in my application, I have to use the following code.
<script src="{{ asset('example1.js') }}" type="text/javascript"></script>
If you want to load image named exampleimage.jpg, You have to use the following code.
<img src="{{ asset('exampleimage.jpg') }}" />
You have to store images, Javascript, and CSS in public folder.
Let me know if it works. According to your question, this is your answer. Let me know if you have any more questions.

Resources