@@ -7,19 +7,19 @@ discard block |
||
7 | 7 | |
8 | 8 | use Illuminate\Http\Request; |
9 | 9 | |
10 | -class PostCommentController extends Controller{ |
|
10 | +class PostCommentController extends Controller { |
|
11 | 11 | |
12 | - public function __construct(){ |
|
12 | + public function __construct() { |
|
13 | 13 | |
14 | 14 | $this->middleware('oauth', ['except' => ['index', 'show']]); |
15 | - $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]); |
|
15 | + $this->middleware('authorize:'.__CLASS__, ['except' => ['index', 'show', 'store']]); |
|
16 | 16 | } |
17 | 17 | |
18 | - public function index($post_id){ |
|
18 | + public function index($post_id) { |
|
19 | 19 | |
20 | 20 | $post = Post::find($post_id); |
21 | 21 | |
22 | - if(!$post){ |
|
22 | + if (!$post) { |
|
23 | 23 | return $this->error("The post with {$post_id} doesn't exist", 404); |
24 | 24 | } |
25 | 25 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | return $this->success($comments, 200); |
28 | 28 | } |
29 | 29 | |
30 | - public function store(Request $request, $post_id){ |
|
30 | + public function store(Request $request, $post_id) { |
|
31 | 31 | |
32 | 32 | $post = Post::find($post_id); |
33 | 33 | |
34 | - if(!$post){ |
|
34 | + if (!$post) { |
|
35 | 35 | return $this->error("The post with {$post_id} doesn't exist", 404); |
36 | 36 | } |
37 | 37 | |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | return $this->success("The comment with id {$comment->id} has been created and assigned to the post with id {$post_id}", 201); |
47 | 47 | } |
48 | 48 | |
49 | - public function update(Request $request, $post_id, $comment_id){ |
|
49 | + public function update(Request $request, $post_id, $comment_id) { |
|
50 | 50 | |
51 | - $comment = Comment::find($comment_id); |
|
52 | - $post = Post::find($post_id); |
|
51 | + $comment = Comment::find($comment_id); |
|
52 | + $post = Post::find($post_id); |
|
53 | 53 | |
54 | - if(!$comment || !$post){ |
|
54 | + if (!$comment || !$post) { |
|
55 | 55 | return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404); |
56 | 56 | } |
57 | 57 | |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | return $this->success("The comment with with id {$comment->id} has been updated", 200); |
67 | 67 | } |
68 | 68 | |
69 | - public function destroy($post_id, $comment_id){ |
|
69 | + public function destroy($post_id, $comment_id) { |
|
70 | 70 | |
71 | - $comment = Comment::find($comment_id); |
|
72 | - $post = Post::find($post_id); |
|
71 | + $comment = Comment::find($comment_id); |
|
72 | + $post = Post::find($post_id); |
|
73 | 73 | |
74 | - if(!$comment || !$post){ |
|
74 | + if (!$comment || !$post) { |
|
75 | 75 | return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404); |
76 | 76 | } |
77 | 77 | |
78 | - if(!$post->comments()->find($comment_id)){ |
|
78 | + if (!$post->comments()->find($comment_id)) { |
|
79 | 79 | return $this->error("The comment with id {$comment_id} isn't assigned to the post with id {$post_id}", 409); |
80 | 80 | } |
81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | return $this->success("The comment with id {$comment_id} has been removed of the post {$post_id}", 200); |
85 | 85 | } |
86 | 86 | |
87 | - public function validateRequest(Request $request){ |
|
87 | + public function validateRequest(Request $request) { |
|
88 | 88 | |
89 | 89 | $rules = [ |
90 | 90 | 'content' => 'required' |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $this->validate($request, $rules); |
94 | 94 | } |
95 | 95 | |
96 | - public function isAuthorized(Request $request){ |
|
96 | + public function isAuthorized(Request $request) { |
|
97 | 97 | |
98 | 98 | $resource = "comments"; |
99 | 99 | $comment = Comment::find($this->getArgs($request)["comment_id"]); |
@@ -7,21 +7,21 @@ discard block |
||
7 | 7 | use Illuminate\Http\Request; |
8 | 8 | use Illuminate\Support\Facades\Hash; |
9 | 9 | |
10 | -class UserController extends Controller{ |
|
10 | +class UserController extends Controller { |
|
11 | 11 | |
12 | - public function __construct(){ |
|
12 | + public function __construct() { |
|
13 | 13 | |
14 | 14 | $this->middleware('oauth', ['except' => ['index', 'show']]); |
15 | - $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show']]); |
|
15 | + $this->middleware('authorize:'.__CLASS__, ['except' => ['index', 'show']]); |
|
16 | 16 | } |
17 | 17 | |
18 | - public function index(){ |
|
18 | + public function index() { |
|
19 | 19 | |
20 | 20 | $users = User::all(); |
21 | 21 | return $this->success($users, 200); |
22 | 22 | } |
23 | 23 | |
24 | - public function store(Request $request){ |
|
24 | + public function store(Request $request) { |
|
25 | 25 | |
26 | 26 | $this->validateRequest($request); |
27 | 27 | |
@@ -33,40 +33,40 @@ discard block |
||
33 | 33 | return $this->success("The user with with id {$user->id} has been created", 201); |
34 | 34 | } |
35 | 35 | |
36 | - public function show($id){ |
|
36 | + public function show($id) { |
|
37 | 37 | |
38 | 38 | $user = User::find($id); |
39 | 39 | |
40 | - if(!$user){ |
|
40 | + if (!$user) { |
|
41 | 41 | return $this->error("The user with {$id} doesn't exist", 404); |
42 | 42 | } |
43 | 43 | |
44 | 44 | return $this->success($user, 200); |
45 | 45 | } |
46 | 46 | |
47 | - public function update(Request $request, $id){ |
|
47 | + public function update(Request $request, $id) { |
|
48 | 48 | |
49 | 49 | $user = User::find($id); |
50 | 50 | |
51 | - if(!$user){ |
|
51 | + if (!$user) { |
|
52 | 52 | return $this->error("The user with {$id} doesn't exist", 404); |
53 | 53 | } |
54 | 54 | |
55 | 55 | $this->validateRequest($request); |
56 | 56 | |
57 | - $user->email = $request->get('email'); |
|
58 | - $user->password = Hash::make($request->get('password')); |
|
57 | + $user->email = $request->get('email'); |
|
58 | + $user->password = Hash::make($request->get('password')); |
|
59 | 59 | |
60 | 60 | $user->save(); |
61 | 61 | |
62 | 62 | return $this->success("The user with with id {$user->id} has been updated", 200); |
63 | 63 | } |
64 | 64 | |
65 | - public function destroy($id){ |
|
65 | + public function destroy($id) { |
|
66 | 66 | |
67 | 67 | $user = User::find($id); |
68 | 68 | |
69 | - if(!$user){ |
|
69 | + if (!$user) { |
|
70 | 70 | return $this->error("The user with {$id} doesn't exist", 404); |
71 | 71 | } |
72 | 72 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | return $this->success("The user with with id {$id} has been deleted", 200); |
76 | 76 | } |
77 | 77 | |
78 | - public function validateRequest(Request $request){ |
|
78 | + public function validateRequest(Request $request) { |
|
79 | 79 | |
80 | 80 | $rules = [ |
81 | 81 | 'email' => 'required|email|unique:users', |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $this->validate($request, $rules); |
86 | 86 | } |
87 | 87 | |
88 | - public function isAuthorized(Request $request){ |
|
88 | + public function isAuthorized(Request $request) { |
|
89 | 89 | |
90 | 90 | $resource = "users"; |
91 | 91 | // $user = User::find($this->getArgs($request)["user_id"]); |
@@ -6,21 +6,21 @@ discard block |
||
6 | 6 | |
7 | 7 | use Illuminate\Http\Request; |
8 | 8 | |
9 | -class PostController extends Controller{ |
|
9 | +class PostController extends Controller { |
|
10 | 10 | |
11 | - public function __construct(){ |
|
11 | + public function __construct() { |
|
12 | 12 | |
13 | 13 | $this->middleware('oauth', ['except' => ['index', 'show']]); |
14 | - $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]); |
|
14 | + $this->middleware('authorize:'.__CLASS__, ['except' => ['index', 'show', 'store']]); |
|
15 | 15 | } |
16 | 16 | |
17 | - public function index(){ |
|
17 | + public function index() { |
|
18 | 18 | |
19 | 19 | $posts = Post::all(); |
20 | 20 | return $this->success($posts, 200); |
21 | 21 | } |
22 | 22 | |
23 | - public function store(Request $request){ |
|
23 | + public function store(Request $request) { |
|
24 | 24 | |
25 | 25 | $this->validateRequest($request); |
26 | 26 | |
@@ -33,28 +33,28 @@ discard block |
||
33 | 33 | return $this->success("The post with with id {$post->id} has been created", 201); |
34 | 34 | } |
35 | 35 | |
36 | - public function show($id){ |
|
36 | + public function show($id) { |
|
37 | 37 | |
38 | 38 | $post = Post::find($id); |
39 | 39 | |
40 | - if(!$post){ |
|
40 | + if (!$post) { |
|
41 | 41 | return $this->error("The post with {$id} doesn't exist", 404); |
42 | 42 | } |
43 | 43 | |
44 | 44 | return $this->success($post, 200); |
45 | 45 | } |
46 | 46 | |
47 | - public function update(Request $request, $id){ |
|
47 | + public function update(Request $request, $id) { |
|
48 | 48 | |
49 | 49 | $post = Post::find($id); |
50 | 50 | |
51 | - if(!$post){ |
|
51 | + if (!$post) { |
|
52 | 52 | return $this->error("The post with {$id} doesn't exist", 404); |
53 | 53 | } |
54 | 54 | |
55 | 55 | $this->validateRequest($request); |
56 | 56 | |
57 | - $post->title = $request->get('title'); |
|
57 | + $post->title = $request->get('title'); |
|
58 | 58 | $post->content = $request->get('content'); |
59 | 59 | $post->user_id = $this->getUserId(); |
60 | 60 | |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | return $this->success("The post with with id {$post->id} has been updated", 200); |
64 | 64 | } |
65 | 65 | |
66 | - public function destroy($id){ |
|
66 | + public function destroy($id) { |
|
67 | 67 | |
68 | 68 | $post = Post::find($id); |
69 | 69 | |
70 | - if(!$post){ |
|
70 | + if (!$post) { |
|
71 | 71 | return $this->error("The post with {$id} doesn't exist", 404); |
72 | 72 | } |
73 | 73 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | return $this->success("The post with with id {$id} has been deleted along with it's comments", 200); |
80 | 80 | } |
81 | 81 | |
82 | - public function validateRequest(Request $request){ |
|
82 | + public function validateRequest(Request $request) { |
|
83 | 83 | |
84 | 84 | $rules = [ |
85 | 85 | 'title' => 'required', |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->validate($request, $rules); |
90 | 90 | } |
91 | 91 | |
92 | - public function isAuthorized(Request $request){ |
|
92 | + public function isAuthorized(Request $request) { |
|
93 | 93 | |
94 | 94 | $resource = "posts"; |
95 | 95 | $post = Post::find($this->getArgs($request)["post_id"]); |