Я хочу отобразить все понравившиеся товары определенного пользователя из базы данных, но я получаю сообщение об ошибке Integrity constraint violation: 1052 Column 'deleted_at' in where clause is ambiguous
. Как я могу отобразить все понравившиеся товары определенного пользователя?
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-файл
@foreach (Auth::user()->likedProducts as $product)
<h2>{{ $product->price }}</h2>
@endforeach