@@ 36-45 (lines=10) @@ | ||
33 | return $this->success("The post with with id {$post->id} has been created", 201); |
|
34 | } |
|
35 | ||
36 | public function show($id){ |
|
37 | ||
38 | $post = Post::find($id); |
|
39 | ||
40 | if(!$post){ |
|
41 | return $this->error("The post with {$id} doesn't exist", 404); |
|
42 | } |
|
43 | ||
44 | return $this->success($post, 200); |
|
45 | } |
|
46 | ||
47 | public function update(Request $request, $id){ |
|
48 | ||
@@ 66-80 (lines=15) @@ | ||
63 | return $this->success("The post with with id {$post->id} has been updated", 200); |
|
64 | } |
|
65 | ||
66 | public function destroy($id){ |
|
67 | ||
68 | $post = Post::find($id); |
|
69 | ||
70 | if(!$post){ |
|
71 | return $this->error("The post with {$id} doesn't exist", 404); |
|
72 | } |
|
73 | ||
74 | // no need to delete the comments for the current post, |
|
75 | // since we used on delete cascase on update cascase. |
|
76 | // $post->comments()->delete(); |
|
77 | $post->delete(); |
|
78 | ||
79 | return $this->success("The post with with id {$id} has been deleted along with it's comments", 200); |
|
80 | } |
|
81 | ||
82 | public function validateRequest(Request $request){ |
|
83 |