@forelse($stocks as $stock) @php $parent_image = null; if (!empty($stock->product) && !empty($stock->product->parent_product_id)) { $parent_image = App\Product::where('id', $stock->product->parent_product_id)->first(); } @endphp