Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add images in laravel view?

Tags:

php

laravel

The thing is, my image is not directly present in my view

Route::Get('saakshar',function() { return view('version1'); }); 

and in my version1.blade.php

<?php include(app_path()."/../resources/views/fronthead.blade.php"); ?> 

I know using php commands in blade file is not efficient or good in any manner, but blade command is not working, but that's not my main problem here.

and in my fronthead.blade.php

<img src='app_path()."/../resources/views/photos/logo.png"' alt="no logo"> 

I haven't learned fully the blade language, so for time being i am using php commands.

But my problem is, why isn't the photo loading in the webpage? Is the URL wrong? Did I place the "photos" folder in the wrong place?

Edit: I've even tried to place the photo is the same folder as fronthead.blade.php and changed the src tag.

I've even tried giving a separate Route::Get() from fronthead.blade.php, but still the problem persists.

like image 311
Vishwanth Iron Heart Avatar asked Apr 06 '16 04:04

Vishwanth Iron Heart


People also ask

Where should I put images in laravel?

Just put your Images in Public Directory (public/... folder or direct images). Public directory is by default rendered by laravel application.


2 Answers

You should store your images, css and JS files in a public directory. To create a link to any of them, use asset() helper:

<img src="{{ asset('img/myimage.png') }}" alt="description of myimage"> 

https://laravel.com/docs/5.1/helpers#method-asset

As alternative, you could use amazing Laravel Collective package for building forms and HTML elements, so your code will look like this:

{{ HTML::image('img/myimage.png', 'a picture') }} 
like image 104
Alexey Mezenin Avatar answered Sep 28 '22 08:09

Alexey Mezenin


If Image folder location is public/assets/img/default.jpg. You can try in view

   <img src="{{ URL::to('/assets/img/default.jpg') }}"> 
like image 44
tanvirjahan Avatar answered Sep 28 '22 09:09

tanvirjahan