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
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire