Julien Machin
Julien Machin

Reputation: 51

Property [medias] does not exist on this collection instance

I have a website that works on localhost, but not on production server.

I got this error :

Property [medias] does not exist on this collection instance

This is a portion of the foreach loop that works on localhost :

 @foreach($critiques  as $critique)
  <div class="max-w-md  bg-white rounded-xl shadow-md overflow-hidden md:max-w-2xl">


  <div class="md:flex">
    <div class="md:shrink-0">

    @if (preg_match('/img/', $critique->medias->picture) ) 
    <img class="h-48 w-full object-cover md:h-full md:w-48"  src="{{ $critique->medias->picture ?? '' }}" alt="{{ $critique->medias->title }}">

@elseif(!preg_match('/img/', $critique->medias->picture)  && $critique->medias->plateform != 'Cinéma' )
<img class="h-48 w-full object-cover md:h-full md:w-48"  src="{{ $critique->medias->picture ?? '' }}" alt="{{ $critique->title }}">

I do not understand what happens.

Upvotes: 0

Views: 41

Answers (1)

Erik Roznbeker
Erik Roznbeker

Reputation: 734

$critique is not an object but a collection. I guess that this is not a simple Model collection but you are doing some manipulation like grouping.

$critiques are probably a collection of collections and you need to do one more loop.

Upvotes: 1

Related Questions