Display images in Laravel - laravel

I can't get the images to display on my laravel website. I have the images in the public/img directory and have tried with
src="{{ url('img/logo.png' }}"
and
{{ HTML::image('img/logo.png') }}
I'm using Laravel 5.2. The url displays correctly in the web console as localhost:8000/img/logo.png but doesn't display the image

I don't know whether it was your typo when writing this post or not, can you try to change your code to:
src="{{ url('img/logo.png') }}"
^
you left out a close bracket
If there is any changes please leave it in comment, I will try to modify my answer.
Hope it helps =)

Related

Handle content which contains laravel blade code in vuejs

#Asking
Help me for my problem,
I have blog content and it has syntax examples like {{ $title }} because my content describes laravel blade.
Problem
When I render my blog content on Vuejs everything goes wrong because there is a sytax blade {{ $title }}
Any solution to this problem?
please use below code
{{ $title }} - use for laravel blade
{{{$title}}} - use for Vue js in laravel blade page
if you want to bind both please try with below code
In script tag
var title = '{{$title}}';
In Vue js CLI
data:return{ title:'{{$title}}' }
If you still getting a problem, then please brief all about your problem with the code I will resolve it.
I try to parse README.md file from hexters/rolevel and I render the README.md content with vuejs, and my apps error and Blank

dont get the right path in laravel for my uploads folder

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

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.

Laravel URL::asset for 404's view

I'm embellishing Laravel's 404 page (ressources/views/erros/404.blade.php). But, I can't load my CSS and JS files, which are, in my public folder.
Actually, Laravel is returning me localhost/css/bootstrap.css when it should return me localhost/myproject/public/css/bootstrap.css with {{ URL::asset('css/bootstrap.css') }}. While it's returning me localhost/myproject/public/css/bootstrap.css when I'm on another view (with the same code: {{ URL::asset('css/bootstrap.css') }}) on my home page wich is perfectly working.
By the way, I'm using Laravel 5.3.
Thanks in advance <3
Configure your webserver so the root of domain (localhost) points to public/ -folder.
Vagrant-solution like Homestead would probably make setting up the development-environment easier for you.

adding images to laravel blades

I m facing strange issue in laravel.
on my local serve it is not accessing this image
http://localhost:8000/img/logo.png
but I can acess this image
http://localhost:8000/img/profile.png
mover over it is not show in code as well any ideas.
Try
<img src="{{ url('img/yourimage.png') }}" alt="">
It will grab the image from your project public folder. It will look like yourwebsite.com/img/yourimage.png and in local server it will look like
http://localhost:8000/img/yourimage.png
2nd Solution:
Try
{{ Html::image('yourimage.png') }}
in laravel there is a inbuilt function url() which is used to ge the path from the public folder of your project. So to show image in your view you can use:
<img src="{{ url('img/yourimage.png') }}" alt="No image found">

Resources