First of all, you first use orderBy to order by created_at and then you use inRandomOrder. What exactly do you want? Additionally you could replace orderBy('created_at', 'DESC') with latest().
Since you only seem to use the first photo from each product, why eager load all photos using with?
Load only the first photo for each product:
@php($firstPhoto = $p->photos()->first())
@if($firstPhoto)
...
data-src="/storage/{{ $firstPhoto->images }}"
...