@@ -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"]); |