dimanche 27 octobre 2019

Displaying liked products from database laravel

I want to display all liked products of a specific user from the database, but I'm getting an error Integrity constraint violation: 1052 Column 'deleted_at' in where clause is ambiguous .How can I display all liked products of specific user?

Like.php

class Like extends Model
{
use SoftDeletes;

protected $table = 'likeables';

protected $fillable = [
    'user_id',
    'likeable_id',
    'likeable_type',
];

/**
 * Get all of the products that are assigned this like.
 */
public function products()
{
    return $this->morphedByMany('App\Product', 'likeable');
}

}

Product.php

   public function likes()
{
    return $this->morphToMany('App\User', 'likeable')->whereDeletedAt(null);
}

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

User.php

public function likedProducts()
{
return $this->morphedByMany('App\Product', 'likeable')->whereDeletedAt(null);
}

Blade file

@foreach (Auth::user()->likedProducts as $product)

<h2></h2>

@endforeach


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

Aucun commentaire:

Enregistrer un commentaire