Saani
Saani

Reputation: 782

Laravel: Image not loading

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 to localhost: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 on localhost/edit/2, any help?

Upvotes: 3

Views: 25605

Answers (3)

user10306682
user10306682

Reputation:

<img src="public/storage/cover_images/image_name.format"  class="img-resposive">

it will load your picture otherwise check the path to image and previlages of the folders you can load image only from a public path due to security reasons

Upvotes: 1

ThomasVdBerge
ThomasVdBerge

Reputation: 8140

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

Upvotes: 9

user4294557
user4294557

Reputation:

try

{{ HTML::image('images/logo.png', 'logo') }}

output will be like

<img src="http://your.url/images/logo.png" alt="logo">

also you can check image path using inspect element in browser

Upvotes: 3

Related Questions