I have the following db structure:
items:
id, name, user_id
users table:
id, name
user_favorites table:
id, user_id, item_id
On my items perm
Let User_favorite
be a model that accesses your user_favorites
table
$result = User_favorite::where('user_id',Auth::getUser()->id)
->where('item_id',$item->id)
->first();
if (is_null($result)) {
// Not favorited - add new
User_favorite::create(['user_id'=>Auth::getUser()->id,'item_id'=>$item->id]);
} else {
// Already favorited - delete the existing
$result->delete();
}