mardi 29 octobre 2019

Undefined property in models laravel

I want to check the product if is liked or not, if the product is liked it will show liked else it will be like. I'm getting an error Undefined property: stdClass::$isLiked I use model to check if the product is liked in the view, how can I fix the problem?

Product.php

 public function getIsLikedAttribute()
 {
    $like = $this->likes()->whereUserId(Auth::id())->first();
    return (!is_null($like)) ? true : false;
 }

Blade file

@foreach($products as $product)
  <h2>USD </h2>
   <h2></h2>

@if ($product->isLiked)
    liked
   @else
    like
   @endif
@endforeach


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2MTd8ql
via IFTTT

Aucun commentaire:

Enregistrer un commentaire