From 51dc52816ff58f4024a04c71f0fa17132e131a48 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 21 Mar 2019 14:26:13 +0100 Subject: [PATCH] Fix logic and add check for duplicated data --- Changelog | 1 + app/Http/Controllers/CartController.php | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index 663e0ef31..585a77ddd 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2019-03-21 DariusIII + * Fix: Fix logic and add check for duplicated data * Chg: Use separate query to add releases to cart as we only need the id, so no need to use heavier getByGuid function * Chg: Update font-awesome to latest version * Chg: Update rtconner/laravel-tagging (3.1.0 => 3.1.1), wildbit/swiftmailer-postmark (3.0.1 => 3.0.2) diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index 57a68ab58..6f7648446 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Models\Release; use App\Models\UsersRelease; +use Illuminate\Database\QueryException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -40,12 +41,15 @@ class CartController extends BasePageController $data = Release::query()->whereIn('guid', $guids)->select(['id'])->get(); - if (! empty($data)) { + if (empty($data)) { return redirect('/cart/index'); } foreach ($data as $d) { - UsersRelease::addCart($this->userdata->id, $d['id']); + $check = UsersRelease::whereReleasesId($d['id'])->first(); + if (empty($check)) { + UsersRelease::addCart($this->userdata->id, $d['id']); + } } return redirect('/cart/index'); }