Laravel: Image not loading
The problem is that when you are on your url, it is not looking for the image in the root folder of your application, but in the current location.
So when you are visiting localhost/edit/2, it is looking for the image in localhost/edit, instead of in localhost.
Try changing your code by adding a slash in the beginning of the image
<a href="{!! URL::to('/') !!}">
<img src="images/logo.png" />
</a>
to
<a href="{!! URL::to('/') !!}">
<img src="/images/logo.png" />
</a>
Additionally, you should actually try the laravel way, like this:
{{ HTML::image('images/logo.png', 'logo') }}
Saani
A versatile and professional web application developer with a commitment to develop & work with innovative & creative web solutions.
Updated on July 30, 2022Comments
-
Saani almost 2 years
I am trying to load an image in Laravel. The image is loading in a
header.blade.php
file. It is working fine on other pages but when it comes tolocalhost:8000/edit/id
, It just doesn't work. I am loading Image like this:<a href="{!! URL::to('/') !!}"> <img src="images/logo.png" /> </a>
My Route:
Route::get('edit/{id}', array('uses' => 'HomeController@edit'));
My Controller:
public function edit($id) { $reg = Register::find($id); $user = User::where('email', Session::get('email'))->first(); if ($reg->user_id == $user->id) { return View::make('edit') ->with('id', $id); } else { return Redirect::to('dashboard')->with('wrong', 'Sorry! Something Went Wrong!'); } }
My image directory:
public/images/logo.png
It is working fine on other pages like
localhost:8000/about
but it doesn't work onlocalhost/edit/2
, any help?