我有以下db结构:
items:
id, name, user_id
users table:
id, name
user_favorites table:
id, user_id, item_id
在我的项目固定链接页面上,我有一个‘添加到收藏夹’按钮,它会在user_favorites
中插入一个新的行
我想能够将它替换为“从收藏夹中删除”按钮,如果用户已经在他们的收藏夹中。
我不明白这背后的逻辑--我是否需要检查user_favorites
中是否存在具有当前用户id和固定链接项id的行?这对我不起作用:
if (Auth::user()->id) {
if (!is_null(DB::table('user_favorites')->where('user_id', '=', Auth::user()->id)->where('item_id', '=', $item->id)->first())) {
// remove from favorites button will show
}
}
https://stackoverflow.com/questions/25209302
复制相似问题