vendredi 13 juillet 2018

how to show only one image in the index page in laravel 5.6?

I have multiple images in my table witch related to vehicle id, like this,

image table
id          fileName        vehicle_id
1            1.jpg             1
2            2.jpg               1
3            3.jpg               1
4            4.jpg               1

vehicle table have maytomany relationship with image table and data grap using eager loader in VehicleController

$vehicles = Vehicle::with('image')->get();
        return view('vechicles.index')->withVehicles($vehicles);

now these images are showing in the vehicles/index.blade.php file

@foreach($vehicle->images as $image)

     <tr>
                    <td><a href=""><img src="/images/"></a></td>

                </tr>

    @endforeach

my problem is occured now, in this way I can show all images in the table which related to proper vechile_id but, I need only show one image like thumbnail to above line. then how can configure this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire