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