I'm working with Laravel 5.8 and in this project I want to show some images that I had uploaded through database like this:
And at the view, I tried this:
<div class="text-center" style="background-image: url('public\images\tavana\{{ $images[0]->path }}');height: 220px;">
But the problem is the image does not load!
However the image already exists at the this directory:
public\images\tavana\imagename.jpg
And other data such as title, subtitle properly shows up.
So how to properly show the image?
use asset to generate url
<div class="text-center" style="background-image: url('{{asset('images/tavana/'.$images[0]->path)}}');height: 220px;background-repeat: no-repeat">
also not sure why you are accessing 0th index $images[0]->path instead you can return first() so it will be $images->path
If you have multiple then use loop
You can't try:
<div class="text-center" style="background-image: url({{url('/')}}.'public/images/tavana/{{ $images[0]->path }}');height: 220px;background-repeat: no-repeat">
Related
Tailwindcss has 2 ways of showing background images:
<div style="background-image: URL();"></div>
<div class="bg-[url('/img/myimage.jpg')]">
This Tailwindcss shows the background image perfectly:
bg-[url('/wp-content/themes/sarasota-soccer-club/images/my-image.jpg')]
but if I try to show an image with an ACF field, it won't work and I have no idea why:
bg-[url(<?php the_field('hero_image'); ?>)] I like this way better because is more elegant. Using style="" in the HTML tag is ugly
but if I use it this way it'll work fine:
style="background-image: url(<?php the_field('hero_image'); ?>);"
So, has anyone found an issue like this with bg-[url(<?php the_field('hero_image'); ?>)]?
I have the following problem. I can't display the image in the blade template. I use bootstrap and laravel 5.8. I've tried different options (without asset, with / ahead). Folder img in public.
Code blade and html from browser below.
blade
<div class="carousel-item-a intro-item bg-image"
style="background-image: url({{asset('img/slide-1.jpg')}})">
chrome
<div class="carousel-item-a intro-item bg-image"
style="background-image: url(http://127.0.0.1:8000/img/slide-1.jpg)">
Try this. Looks like you should concatenate string with php code.
<div class="carousel-item-a intro-item bg-image"
style="background-image:url('". {{asset('img/slide-1.jpg')}}."')">
i have different type of users in my application and each user have differerent type of background image for their wall like facebook but here i am confused ho to chang each user background image dynamically as their images name are coming from database and background image class is defined in css file . any solution will be highly appreciated as i am new to laravel and php . thnks
as for laravel blade template engine the code will be like this
#if(isset($data->coverphoto))
<img src="{{asset('$data->coverphoto')}}" title="" />
#elseif(empty($data->coverphoto) || $data->coverphoto == null)
<img src="asset('placeholder.jpg')" title="" />
#endif
first we will check if the data is existing or not then we will place image as a img tag another option is that we will use class like
.coverphoto{
background-image: url('<?= (isset($data->coverphoto))?asset('images/') . $data->coverphoto: asset('images/placeholder.jpg') ?>');
}
<div class="coverphoto"> </div>
Hi i am using Codeigniter(i am fairly new) and i have a problem displaying data(actually a path from the database) to View B but lets take it from the beggining. I am making a cinema web page and I want a user to click on a link and then get the appropriate redirect to another link which will display the movie that clicked. I am getting the movie name from the database and manage to send it to the Controller B as a parameter and get the image path that i want to display in order to show the picture. But the web page does not show the picture although the path is already sent(i have checked it on Firefox fire bug and to a blank page just to make sure the the path is sent) Btw when i load the page the method and parameter appears on the url but when i delete the parameter and the method from the url and hit enter the path works perfectly displaying the image. Any help?
ps I am a rookie
This is from view a
<div class="movie__images">
<a href="<?php echo base_url()?>movie_page_full/get_user_click_info/<?php echo $movie_data[6]->title ?>" class="movie-beta__link">
<img alt='' src=<?php echo $now1 ?>>
</a>
</div>
This is from controller b
public function get_user_click_info(){
$this->load->model('movie_page_full_model');
$decoded_movie_name = $this->uri->segment(3);
$query_data = $this->movie_page_full_model->get_single_movie_data($decoded_movie_name);
$data['path'] = $query_data[0]->path;
$this->load->view('templates/header');
$this->load->view('Home/view_movie_page_full',$data);
$this->load->view('templates/footer_movie_page_full');
}
This is from the view b where i send the path from the controller b
<div class="col-sm-4 col-md-3 movie-mobile">
<div class="movie__images">
<img alt="" src=<?php echo $path ?>>
</div>
</div>
A proof that the path is send to the HTML code but does not show it
The url (Gravity is the name of the movie)
I found the answer to my question. I discovered that when i was changing controllers and loading the image, the path was displaying properly but actually it was missing the full url as i was leaving from the homepage that i set as the base url so the only thing that i had to do, was to use the variable that contains the path inside the codeigniter base url. Base url actually appends the rest of missing part. Below is the correct code block.
<div class="col-sm-4 col-md-3 movie-mobile">
<div class="movie__images">
<img alt="" src=<?php echo base_url($path)?>>
</div>
</div>
I am making a web page on laravel 5, I haven't used laravel since it was at 3 but I really like the new features that it has.
Everything its working fine on an app that it's almost finished, but I have a problem with images.
I am trying to display an image to a view and it's just not showing, I get the little image icon that we all know.
I have used all the methods that I have found on larval docks and in the forums.
including:
assets
URL
HTML (It didn0t work at all)
Direct Url in the view
I am actually using just Artsian serve so the URL would be something like:
http://localhost:8000/uploads/images/posts/1456814127.jpg
The folder its un public folder so in my opinion its the correct url.
With diffrent methos i aslo called the image from the pc path and its the same result. I am using intervention to upload the image by the way.
Any idea?
EDIT:
Ok i tried on localhost of wamp server and the image output worked. I dont know why but it did.
EDIT 2:
I am on laravel Homestead now, and it's still not working. I am angry by this point. Please help me!!
Here it's my Controller:
public function posts()
{
$posts = DB::table('posts')->paginate(3);
//page heading
$title = 'Latest Posts';
return view('frontend.posts.index')->with(compact('posts', 'title'));
}
This it's my view:
<a href="#" class="image">
<img src="{{ asset('uploads/images/posts/'.$post->post_image) }}" class="img-rounded">
<span class="hover-zoom"></span>
</a>
At laravel homestead the output link it's:
http://krubbit.dev/uploads/images/posts/1457074877.jpg
The dir structure of the image location:
-Laravel-dir
-Public
-Uploads
-images
-posts
-1457074877.jpg
Something like this
<img src="{{ asset('uploads/images/posts/1456814127.jpg') }}" />
Please use url funcion of Laravel as shown below
<a href="#" class="image">
<img src="{{url('asset/uploads/images/posts/'.$post->post_image)}}" class="img-rounded">
<span class="hover-zoom"></span>
</a>
Hope this will help..!!