From a230265d7b97880f1feaca5c4dd764da8a78772d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 5 Aug 2018 13:18:33 -0600 Subject: [PATCH] Update BookmarkController --- app/Http/Controllers/BookmarkController.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/BookmarkController.php b/app/Http/Controllers/BookmarkController.php index 17c788d0..fb374dbc 100644 --- a/app/Http/Controllers/BookmarkController.php +++ b/app/Http/Controllers/BookmarkController.php @@ -16,23 +16,27 @@ class BookmarkController extends Controller public function store(Request $request) { $this->validate($request, [ - 'item' => 'required|integer|min:1' + 'item' => 'required|integer|min:1' ]); $profile = Auth::user()->profile; $status = Status::findOrFail($request->input('item')); $bookmark = Bookmark::firstOrCreate( - ['status_id' => $status->id], ['profile_id' => $profile->id] + ['status_id' => $status->id], ['profile_id' => $profile->id] ); + if(!$bookmark->wasRecentlyCreated) { + $bookmark->delete(); + } + if($request->ajax()) { $response = ['code' => 200, 'msg' => 'Bookmark saved!']; - } else { + } else { $response = redirect()->back(); - } + } - return $response; - } + return $response; + } }