| Conditions | 3 |
| Paths | 3 |
| Total Lines | 26 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | public function __invoke(TipBookmarkRequest $request) |
||
| 16 | { |
||
| 17 | if($request->state) |
||
| 18 | { |
||
| 19 | try |
||
| 20 | { |
||
| 21 | UserTechTipBookmark::create([ |
||
| 22 | 'user_id' => $request->user()->user_id, |
||
| 23 | 'tip_id' => $request->tip_id, |
||
| 24 | ]); |
||
| 25 | } |
||
| 26 | catch(Exception $e) |
||
| 27 | { |
||
| 28 | // If for some reason the add fails, trigger error |
||
| 29 | report('User '.$request->user()->username.' is trying to bookmark a Tech Tip that is already bookmarked'); |
||
| 30 | report($e); |
||
| 31 | abort(409, 'Bookmark already exists'); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | else |
||
| 35 | { |
||
| 36 | // Remove the bookmark |
||
| 37 | UserTechTipBookmark::where('user_id', $request->user()->user_id)->where('tip_id', $request->tip_id)->first()->delete(); |
||
| 38 | } |
||
| 39 | |||
| 40 | return response()->noContent(); |
||
| 41 | } |
||
| 43 |