Update BookmarkController

This commit is contained in:
Daniel Supernault 2018-08-05 13:18:33 -06:00
parent 86d7d1a928
commit a230265d7b

View file

@ -16,23 +16,27 @@ class BookmarkController extends Controller
public function store(Request $request) public function store(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'item' => 'required|integer|min:1' 'item' => 'required|integer|min:1'
]); ]);
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
$status = Status::findOrFail($request->input('item')); $status = Status::findOrFail($request->input('item'));
$bookmark = Bookmark::firstOrCreate( $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()) { if($request->ajax()) {
$response = ['code' => 200, 'msg' => 'Bookmark saved!']; $response = ['code' => 200, 'msg' => 'Bookmark saved!'];
} else { } else {
$response = redirect()->back(); $response = redirect()->back();
} }
return $response; return $response;
} }
} }