My Upload Model is
class Upload extends Model
{
public function vehicle()
{
return $this->belongsTo(Vehicle::class);
}
}
I have multiple images in my uploads table with related to vehicle_id, as foreign key like this,
uploads table
id fileName vehicle_id
1 1.jpg 1
2 2.jpg 1
3 3.jpg 1
4 4.jpg 1
5 28.png 2
6 28.png 2
7 29.png 2
8 30.png 3
9 31.png 3
10 56.png 3
The vehicle table have many to many relationship with the image table and data grap using eager loader in VehicleController,
$vehicles = Vehicle::with('uploads')->get();
return view('vechicles.index')->withVehicles($vehicles);
Now these images are showing in the vehicles/index.blade.php file
@foreach($vehicle->uploads as $upload)
<tr>
<td><a href="{{route('vechicles.show',$vehicle->id)}}"><img src="/images/{{ $upload->resized_name }}"></a></td>
</tr>
@endforeach
My problem is occurred now, in this way, I can show all images in the table whith related to proper vehicle_id but, I need only show one image (to matching vehicle_id) like thumbnail to above line. Then how can I configure this? actually I need only one image to print in index.blade.php to related in each vehicle_id, as an example here are 4 images with related to vehicle_id 1. but I need only print decending oder one image to print and same to vehicle_id 2 and etc.... how can do this?
Please or to participate in this conversation.