How to integrate the images from a url into the database and using laravel

0

The following code is a test to access the database of my server and I would like to know how to implement an image using the url that is in the tables of my database, I know that I must use the asset method that allows me to access the images found in the asset folder but I do not know how to concatenate it properly

    <h1>Listado de Libros</h1>
@foreach($producto as $producto)
<h3>{{ $producto->titulo }}</h3>
<img src="{{asset(img/$producto->imagen)}}" alt="productoimagen" width="250">
@endforeach
    
asked by Miguel C 14.05.2018 в 22:07
source

1 answer

0
<img src="{{ asset('img/'.$producto->imagen) }}" alt="productoimagen" width="250">

Edit

With helper asset() , what laravel does is build the complete URL to the path that you pass as a parameter. That is, concatenates your domain name or server, in front of the path that you pass by parameter.

For example, if you call asset('img/logo.png') , the function will return http://tu_servidor.com/img/logo.png .

Therefore, in your root of the application, inside the public/ folder, you have to have an image folder img/ (depending on what you're going to the asset() function), and within her, the image that is returning you $producto->imagen .

PD. If something is not clear to you, ask without having to make a downvote.

    
answered by 15.05.2018 / 14:25
source