Completed
Push — master ( 43d6b6...7fd3dc )
by Sherif
12:33
created
src/Modules/V1/Acl/Http/Controllers/UsersController.php 1 patch
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -8,268 +8,268 @@
 block discarded – undo
8 8
 
9 9
 class UsersController extends BaseApiController
10 10
 {
11
-    /**
12
-     * The name of the model that is used by the base api controller 
13
-     * to preform actions like (add, edit ... etc).
14
-     * @var string
15
-     */
16
-    protected $model               = 'users';
17
-
18
-    /**
19
-     * List of all route actions that the base api controller
20
-     * will skip permissions check for them.
21
-     * @var array
22
-     */
23
-    protected $skipPermissionCheck = ['account', 'logout', 'changePassword'];
24
-
25
-    /**
26
-     * List of all route actions that the base api controller
27
-     * will skip login check for them.
28
-     * @var array
29
-     */
30
-    protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken'];
31
-
32
-    /**
33
-     * The validations rules used by the base api controller
34
-     * to check before add.
35
-     * @var array
36
-     */
37
-    protected $validationRules     = [
38
-        'name'     => 'nullable|string', 
39
-        'email'    => 'required|email|unique:users,email,{id}', 
40
-        'password' => 'nullable|min:6'
41
-    ];
42
-
43
-    /**
44
-     * The loginProxy implementation.
45
-     * 
46
-     * @var \App\Modules\V1\Acl\Proxy\LoginProxy
47
-     */
48
-    protected $loginProxy;
49
-
50
-    public function __construct(LoginProxy $loginProxy)
51
-    {        
52
-        $this->loginProxy = $loginProxy;
53
-        parent::__construct();
54
-    }
55
-
56
-    /**
57
-     * Return the logged in user account.
58
-     * 
59
-     * @return \Illuminate\Http\Response
60
-     */
61
-    public function account()
62
-    {
63
-        return \Response::json($this->repo->account($this->relations), 200);
64
-    }
65
-
66
-    /**
67
-     * Block the user.
68
-     *
69
-     * @param  integer  $id Id of the user.
70
-     * @return \Illuminate\Http\Response
71
-     */
72
-    public function block($id)
73
-    {
74
-        return \Response::json($this->repo->block($id), 200);
75
-    }
76
-
77
-    /**
78
-     * Unblock the user.
79
-     *
80
-     * @param  integer  $id Id of the user.
81
-     * @return \Illuminate\Http\Response
82
-     */
83
-    public function unblock($id)
84
-    {
85
-        return \Response::json($this->repo->unblock($id), 200);
86
-    }
87
-
88
-    /**
89
-     * Logout the user.
90
-     * 
91
-     * @return \Illuminate\Http\Response
92
-     */
93
-    public function logout()
94
-    {
95
-        return \Response::json($this->loginProxy->logout(), 200);
96
-    }
97
-
98
-    /**
99
-     * Handle a registration request.
100
-     *
101
-     * @param  \Illuminate\Http\Request  $request
102
-     * @return \Illuminate\Http\Response
103
-     */
104
-    public function register(Request $request)
105
-    {
106
-        $this->validate($request, [
107
-            'name'     => 'nullable|string', 
108
-            'email'    => 'required|email|unique:users,email,{id}', 
109
-            'password' => 'required|min:6'
110
-            ]);
111
-
112
-        return \Response::json($this->repo->register($request->only('email', 'password')), 200);
113
-    }
114
-
115
-    /**
116
-     * Handle a login request to the application.
117
-     *
118
-     * @param  \Illuminate\Http\Request  $request
119
-     * @return \Illuminate\Http\Response
120
-     */
121
-    public function login(Request $request)
122
-    {
123
-        $this->validate($request, [
124
-            'email'    => 'required|email', 
125
-            'password' => 'required|min:6',
126
-            'admin'    => 'boolean'
127
-            ]);
128
-
129
-        return \Response::json($this->loginProxy->login($request->only('email', 'password'), $request->get('admin')), 200);
130
-    }
131
-
132
-    /**
133
-     * Handle a social login request of the none admin to the application.
134
-     *
135
-     * @param  \Illuminate\Http\Request  $request
136
-     * @return \Illuminate\Http\Response
137
-     */
138
-    public function loginSocial(Request $request)
139
-    {
140
-        $this->validate($request, [
141
-            'auth_code'    => 'required_without:access_token',
142
-            'access_token' => 'required_without:auth_code',
143
-            'type'         => 'required|in:facebook,google'
144
-            ]);
145
-
146
-        return \Response::json($this->repo->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
147
-    }
148
-
149
-    /**
150
-     * Assign the given groups to the given user.
151
-     *
152
-     * @param  \Illuminate\Http\Request  $request
153
-     * @return \Illuminate\Http\Response
154
-     */
155
-    public function assigngroups(Request $request)
156
-    {
157
-        $this->validate($request, [
158
-            'group_ids' => 'required|exists:groups,id', 
159
-            'user_id'   => 'required|exists:users,id'
160
-            ]);
161
-
162
-        return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
163
-    }
164
-
165
-    /**
166
-     * Send a reset link to the given user.
167
-     *
168
-     * @param  \Illuminate\Http\Request  $request
169
-     * @return \Illuminate\Http\Response
170
-     */
171
-    public function sendreset(Request $request)
172
-    {
173
-        $this->validate($request, ['email' => 'required|email']);
174
-
175
-        return \Response::json($this->repo->sendReset($request->only('email')), 200);
176
-    }
177
-
178
-    /**
179
-     * Reset the given user's password.
180
-     *
181
-     * @param  \Illuminate\Http\Request  $request
182
-     * @return \Illuminate\Http\Response
183
-     */
184
-    public function resetpassword(Request $request)
185
-    {
186
-        $this->validate($request, [
187
-            'token'                 => 'required',
188
-            'email'                 => 'required|email',
189
-            'password'              => 'required|confirmed|min:6',
190
-            'password_confirmation' => 'required',
191
-        ]);
192
-
193
-        return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
194
-    }
195
-
196
-    /**
197
-     * Change the logged in user password.
198
-     *
199
-     * @param  \Illuminate\Http\Request  $request
200
-     * @return \Illuminate\Http\Response
201
-     */
202
-    public function changePassword(Request $request)
203
-    {
204
-        $this->validate($request, [
205
-            'old_password'          => 'required',
206
-            'password'              => 'required|confirmed|min:6',
207
-            'password_confirmation' => 'required',
208
-        ]);
209
-
210
-        return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
211
-    }
212
-
213
-    /**
214
-     * Refresh the expired login token.
215
-     *
216
-     * @param  \Illuminate\Http\Request  $request
217
-     * @return \Illuminate\Http\Response
218
-     */
219
-    public function refreshtoken(Request $request)
220
-    {
221
-        $this->validate($request, [
222
-            'refreshtoken' => 'required',
223
-        ]);
224
-
225
-        return \Response::json($this->loginProxy->refreshtoken($request->only('refreshtoken')), 200);
226
-    }
227
-
228
-    /**
229
-     * Paginate all users with inthe given group.
230
-     * 
231
-     * @param  \Illuminate\Http\Request  $request
232
-     * @param  string $groupName The name of the requested group.
233
-     * @param  integer $perPage  Number of rows per page default 15.
234
-     * @param  string  $sortBy   The name of the column to sort by.
235
-     * @param  boolean $desc     Sort ascending or descinding (1: desc, 0: asc).
236
-     * @return \Illuminate\Http\Response
237
-     */
238
-    public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1)
239
-    {
240
-        return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200);
241
-    }
242
-
243
-    /**
244
-     * Save the given data to the logged in user.
245
-     *
246
-     * @param  \Illuminate\Http\Request  $request
247
-     * @return \Illuminate\Http\Response
248
-     */
249
-    public function saveProfile(Request $request) 
250
-    {
251
-        foreach ($this->validationRules as &$rule) 
252
-        {
253
-            if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
254
-            {
255
-                $rule .= ',deleted_at,NULL';
256
-            }
257
-
258
-            if ($request->has('id')) 
259
-            {
260
-                $rule = str_replace('{id}', $request->get('id'), $rule);
261
-            }
262
-            else
263
-            {
264
-                $rule = str_replace(',{id}', '', $rule);
265
-            }
266
-        }
267
-
268
-        $this->validate($request, $this->validationRules);
269
-
270
-        if ($this->model)
271
-        {
272
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200);
273
-        }
274
-    }
11
+	/**
12
+	 * The name of the model that is used by the base api controller 
13
+	 * to preform actions like (add, edit ... etc).
14
+	 * @var string
15
+	 */
16
+	protected $model               = 'users';
17
+
18
+	/**
19
+	 * List of all route actions that the base api controller
20
+	 * will skip permissions check for them.
21
+	 * @var array
22
+	 */
23
+	protected $skipPermissionCheck = ['account', 'logout', 'changePassword'];
24
+
25
+	/**
26
+	 * List of all route actions that the base api controller
27
+	 * will skip login check for them.
28
+	 * @var array
29
+	 */
30
+	protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken'];
31
+
32
+	/**
33
+	 * The validations rules used by the base api controller
34
+	 * to check before add.
35
+	 * @var array
36
+	 */
37
+	protected $validationRules     = [
38
+		'name'     => 'nullable|string', 
39
+		'email'    => 'required|email|unique:users,email,{id}', 
40
+		'password' => 'nullable|min:6'
41
+	];
42
+
43
+	/**
44
+	 * The loginProxy implementation.
45
+	 * 
46
+	 * @var \App\Modules\V1\Acl\Proxy\LoginProxy
47
+	 */
48
+	protected $loginProxy;
49
+
50
+	public function __construct(LoginProxy $loginProxy)
51
+	{        
52
+		$this->loginProxy = $loginProxy;
53
+		parent::__construct();
54
+	}
55
+
56
+	/**
57
+	 * Return the logged in user account.
58
+	 * 
59
+	 * @return \Illuminate\Http\Response
60
+	 */
61
+	public function account()
62
+	{
63
+		return \Response::json($this->repo->account($this->relations), 200);
64
+	}
65
+
66
+	/**
67
+	 * Block the user.
68
+	 *
69
+	 * @param  integer  $id Id of the user.
70
+	 * @return \Illuminate\Http\Response
71
+	 */
72
+	public function block($id)
73
+	{
74
+		return \Response::json($this->repo->block($id), 200);
75
+	}
76
+
77
+	/**
78
+	 * Unblock the user.
79
+	 *
80
+	 * @param  integer  $id Id of the user.
81
+	 * @return \Illuminate\Http\Response
82
+	 */
83
+	public function unblock($id)
84
+	{
85
+		return \Response::json($this->repo->unblock($id), 200);
86
+	}
87
+
88
+	/**
89
+	 * Logout the user.
90
+	 * 
91
+	 * @return \Illuminate\Http\Response
92
+	 */
93
+	public function logout()
94
+	{
95
+		return \Response::json($this->loginProxy->logout(), 200);
96
+	}
97
+
98
+	/**
99
+	 * Handle a registration request.
100
+	 *
101
+	 * @param  \Illuminate\Http\Request  $request
102
+	 * @return \Illuminate\Http\Response
103
+	 */
104
+	public function register(Request $request)
105
+	{
106
+		$this->validate($request, [
107
+			'name'     => 'nullable|string', 
108
+			'email'    => 'required|email|unique:users,email,{id}', 
109
+			'password' => 'required|min:6'
110
+			]);
111
+
112
+		return \Response::json($this->repo->register($request->only('email', 'password')), 200);
113
+	}
114
+
115
+	/**
116
+	 * Handle a login request to the application.
117
+	 *
118
+	 * @param  \Illuminate\Http\Request  $request
119
+	 * @return \Illuminate\Http\Response
120
+	 */
121
+	public function login(Request $request)
122
+	{
123
+		$this->validate($request, [
124
+			'email'    => 'required|email', 
125
+			'password' => 'required|min:6',
126
+			'admin'    => 'boolean'
127
+			]);
128
+
129
+		return \Response::json($this->loginProxy->login($request->only('email', 'password'), $request->get('admin')), 200);
130
+	}
131
+
132
+	/**
133
+	 * Handle a social login request of the none admin to the application.
134
+	 *
135
+	 * @param  \Illuminate\Http\Request  $request
136
+	 * @return \Illuminate\Http\Response
137
+	 */
138
+	public function loginSocial(Request $request)
139
+	{
140
+		$this->validate($request, [
141
+			'auth_code'    => 'required_without:access_token',
142
+			'access_token' => 'required_without:auth_code',
143
+			'type'         => 'required|in:facebook,google'
144
+			]);
145
+
146
+		return \Response::json($this->repo->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
147
+	}
148
+
149
+	/**
150
+	 * Assign the given groups to the given user.
151
+	 *
152
+	 * @param  \Illuminate\Http\Request  $request
153
+	 * @return \Illuminate\Http\Response
154
+	 */
155
+	public function assigngroups(Request $request)
156
+	{
157
+		$this->validate($request, [
158
+			'group_ids' => 'required|exists:groups,id', 
159
+			'user_id'   => 'required|exists:users,id'
160
+			]);
161
+
162
+		return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
163
+	}
164
+
165
+	/**
166
+	 * Send a reset link to the given user.
167
+	 *
168
+	 * @param  \Illuminate\Http\Request  $request
169
+	 * @return \Illuminate\Http\Response
170
+	 */
171
+	public function sendreset(Request $request)
172
+	{
173
+		$this->validate($request, ['email' => 'required|email']);
174
+
175
+		return \Response::json($this->repo->sendReset($request->only('email')), 200);
176
+	}
177
+
178
+	/**
179
+	 * Reset the given user's password.
180
+	 *
181
+	 * @param  \Illuminate\Http\Request  $request
182
+	 * @return \Illuminate\Http\Response
183
+	 */
184
+	public function resetpassword(Request $request)
185
+	{
186
+		$this->validate($request, [
187
+			'token'                 => 'required',
188
+			'email'                 => 'required|email',
189
+			'password'              => 'required|confirmed|min:6',
190
+			'password_confirmation' => 'required',
191
+		]);
192
+
193
+		return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
194
+	}
195
+
196
+	/**
197
+	 * Change the logged in user password.
198
+	 *
199
+	 * @param  \Illuminate\Http\Request  $request
200
+	 * @return \Illuminate\Http\Response
201
+	 */
202
+	public function changePassword(Request $request)
203
+	{
204
+		$this->validate($request, [
205
+			'old_password'          => 'required',
206
+			'password'              => 'required|confirmed|min:6',
207
+			'password_confirmation' => 'required',
208
+		]);
209
+
210
+		return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
211
+	}
212
+
213
+	/**
214
+	 * Refresh the expired login token.
215
+	 *
216
+	 * @param  \Illuminate\Http\Request  $request
217
+	 * @return \Illuminate\Http\Response
218
+	 */
219
+	public function refreshtoken(Request $request)
220
+	{
221
+		$this->validate($request, [
222
+			'refreshtoken' => 'required',
223
+		]);
224
+
225
+		return \Response::json($this->loginProxy->refreshtoken($request->only('refreshtoken')), 200);
226
+	}
227
+
228
+	/**
229
+	 * Paginate all users with inthe given group.
230
+	 * 
231
+	 * @param  \Illuminate\Http\Request  $request
232
+	 * @param  string $groupName The name of the requested group.
233
+	 * @param  integer $perPage  Number of rows per page default 15.
234
+	 * @param  string  $sortBy   The name of the column to sort by.
235
+	 * @param  boolean $desc     Sort ascending or descinding (1: desc, 0: asc).
236
+	 * @return \Illuminate\Http\Response
237
+	 */
238
+	public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1)
239
+	{
240
+		return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200);
241
+	}
242
+
243
+	/**
244
+	 * Save the given data to the logged in user.
245
+	 *
246
+	 * @param  \Illuminate\Http\Request  $request
247
+	 * @return \Illuminate\Http\Response
248
+	 */
249
+	public function saveProfile(Request $request) 
250
+	{
251
+		foreach ($this->validationRules as &$rule) 
252
+		{
253
+			if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
254
+			{
255
+				$rule .= ',deleted_at,NULL';
256
+			}
257
+
258
+			if ($request->has('id')) 
259
+			{
260
+				$rule = str_replace('{id}', $request->get('id'), $rule);
261
+			}
262
+			else
263
+			{
264
+				$rule = str_replace(',{id}', '', $rule);
265
+			}
266
+		}
267
+
268
+		$this->validate($request, $this->validationRules);
269
+
270
+		if ($this->model)
271
+		{
272
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200);
273
+		}
274
+	}
275 275
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Interfaces/RepositoryInterface.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -2,118 +2,118 @@
 block discarded – undo
2 2
 
3 3
 interface RepositoryInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     * 
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 * 
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
15 15
     
16
-    /**
17
-     * Fetch all records with relations from storage in pages 
18
-     * that matche the given query.
19
-     * 
20
-     * @param  string  $query
21
-     * @param  integer $perPage
22
-     * @param  array   $relations
23
-     * @param  array   $sortBy
24
-     * @param  array   $desc
25
-     * @param  array   $columns
26
-     * @return collection
27
-     */
28
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
16
+	/**
17
+	 * Fetch all records with relations from storage in pages 
18
+	 * that matche the given query.
19
+	 * 
20
+	 * @param  string  $query
21
+	 * @param  integer $perPage
22
+	 * @param  array   $relations
23
+	 * @param  array   $sortBy
24
+	 * @param  array   $desc
25
+	 * @param  array   $columns
26
+	 * @return collection
27
+	 */
28
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
29 29
 
30
-    /**
31
-     * Fetch all records with relations from storage in pages.
32
-     * 
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
30
+	/**
31
+	 * Fetch all records with relations from storage in pages.
32
+	 * 
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
41 41
     
42
-    /**
43
-     * Fetch all records with relations based on
44
-     * the given condition from storage in pages.
45
-     * 
46
-     * @param  array   $conditions array of conditions
47
-     * @param  integer $perPage
48
-     * @param  array   $relations
49
-     * @param  array   $sortBy
50
-     * @param  array   $desc
51
-     * @param  array   $columns
52
-     * @return collection
53
-     */
54
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
42
+	/**
43
+	 * Fetch all records with relations based on
44
+	 * the given condition from storage in pages.
45
+	 * 
46
+	 * @param  array   $conditions array of conditions
47
+	 * @param  integer $perPage
48
+	 * @param  array   $relations
49
+	 * @param  array   $sortBy
50
+	 * @param  array   $desc
51
+	 * @param  array   $columns
52
+	 * @return collection
53
+	 */
54
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
55 55
 
56
-     /**
57
-     * Save the given model/models to the storage.
58
-     * 
59
-     * @param  array   $data
60
-     * @return object
61
-     */
62
-    public function save(array $data);
56
+	 /**
57
+	  * Save the given model/models to the storage.
58
+	  * 
59
+	  * @param  array   $data
60
+	  * @return object
61
+	  */
62
+	public function save(array $data);
63 63
 
64
-    /**
65
-     * Update record in the storage based on the given
66
-     * condition.
67
-     * 
68
-     * @param  var     $value condition value
69
-     * @param  array   $data
70
-     * @param  string  $attribute condition column name
71
-     * @return integer affected rows
72
-     */
73
-    public function update($value, array $data, $attribute = 'id');
64
+	/**
65
+	 * Update record in the storage based on the given
66
+	 * condition.
67
+	 * 
68
+	 * @param  var     $value condition value
69
+	 * @param  array   $data
70
+	 * @param  string  $attribute condition column name
71
+	 * @return integer affected rows
72
+	 */
73
+	public function update($value, array $data, $attribute = 'id');
74 74
 
75
-    /**
76
-     * Delete record from the storage based on the given
77
-     * condition.
78
-     * 
79
-     * @param  var     $value condition value
80
-     * @param  string  $attribute condition column name
81
-     * @return integer affected rows
82
-     */
83
-    public function delete($value, $attribute = 'id');
75
+	/**
76
+	 * Delete record from the storage based on the given
77
+	 * condition.
78
+	 * 
79
+	 * @param  var     $value condition value
80
+	 * @param  string  $attribute condition column name
81
+	 * @return integer affected rows
82
+	 */
83
+	public function delete($value, $attribute = 'id');
84 84
     
85
-    /**
86
-     * Fetch records from the storage based on the given
87
-     * id.
88
-     * 
89
-     * @param  integer $id
90
-     * @param  array   $relations
91
-     * @param  array   $columns
92
-     * @return object
93
-     */
94
-    public function find($id, $relations = [], $columns = array('*'));
85
+	/**
86
+	 * Fetch records from the storage based on the given
87
+	 * id.
88
+	 * 
89
+	 * @param  integer $id
90
+	 * @param  array   $relations
91
+	 * @param  array   $columns
92
+	 * @return object
93
+	 */
94
+	public function find($id, $relations = [], $columns = array('*'));
95 95
     
96
-    /**
97
-     * Fetch records from the storage based on the given
98
-     * condition.
99
-     * 
100
-     * @param  array   $conditions array of conditions
101
-     * @param  array   $relations
102
-     * @param  array   $sortBy
103
-     * @param  array   $desc
104
-     * @param  array   $columns
105
-     * @return collection
106
-     */
107
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
96
+	/**
97
+	 * Fetch records from the storage based on the given
98
+	 * condition.
99
+	 * 
100
+	 * @param  array   $conditions array of conditions
101
+	 * @param  array   $relations
102
+	 * @param  array   $sortBy
103
+	 * @param  array   $desc
104
+	 * @param  array   $columns
105
+	 * @return collection
106
+	 */
107
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
108 108
 
109
-    /**
110
-     * Fetch the first record fro the storage based on the given
111
-     * condition.
112
-     * 
113
-     * @param  array   $conditions array of conditions
114
-     * @param  array   $relations
115
-     * @param  array   $columns
116
-     * @return object
117
-     */
118
-    public function first($conditions, $relations = [], $columns = array('*'));
109
+	/**
110
+	 * Fetch the first record fro the storage based on the given
111
+	 * condition.
112
+	 * 
113
+	 * @param  array   $conditions array of conditions
114
+	 * @param  array   $relations
115
+	 * @param  array   $columns
116
+	 * @return object
117
+	 */
118
+	public function first($conditions, $relations = [], $columns = array('*'));
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/Console/Commands/GenerateDoc.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -6,272 +6,272 @@
 block discarded – undo
6 6
 
7 7
 class GenerateDoc extends Command
8 8
 {
9
-    /**
10
-     * The name and signature of the console command.
11
-     *
12
-     * @var string
13
-     */
14
-    protected $signature = 'doc:generate';
9
+	/**
10
+	 * The name and signature of the console command.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	protected $signature = 'doc:generate';
15 15
 
16
-    /**
17
-     * The console command description.
18
-     *
19
-     * @var string
20
-     */
21
-    protected $description = 'Generate api documentation';
16
+	/**
17
+	 * The console command description.
18
+	 *
19
+	 * @var string
20
+	 */
21
+	protected $description = 'Generate api documentation';
22 22
 
23
-    /**
24
-     * Create a new command instance.
25
-     *
26
-     * @return void
27
-     */
28
-    public function __construct()
29
-    {
30
-        parent::__construct();
31
-    }
23
+	/**
24
+	 * Create a new command instance.
25
+	 *
26
+	 * @return void
27
+	 */
28
+	public function __construct()
29
+	{
30
+		parent::__construct();
31
+	}
32 32
 
33
-    /**
34
-     * Execute the console command.
35
-     *
36
-     * @return mixed
37
-     */
38
-    public function handle()
39
-    {
40
-        $docData           = [];
41
-        $docData['models'] = [];
42
-        $routes            = $this->getRoutes();
43
-        foreach ($routes as $route) 
44
-        {
45
-            if ($route) 
46
-            {
47
-                $actoinArray       = explode('@', $route['action']);
48
-                $controller        = $actoinArray[0];
49
-                $method            = $actoinArray[1];
50
-                $route['name']     = $method !== 'index' ? $method : 'list';
33
+	/**
34
+	 * Execute the console command.
35
+	 *
36
+	 * @return mixed
37
+	 */
38
+	public function handle()
39
+	{
40
+		$docData           = [];
41
+		$docData['models'] = [];
42
+		$routes            = $this->getRoutes();
43
+		foreach ($routes as $route) 
44
+		{
45
+			if ($route) 
46
+			{
47
+				$actoinArray       = explode('@', $route['action']);
48
+				$controller        = $actoinArray[0];
49
+				$method            = $actoinArray[1];
50
+				$route['name']     = $method !== 'index' ? $method : 'list';
51 51
                 
52
-                $reflectionClass   = new \ReflectionClass($controller);
53
-                $reflectionMethod  = $reflectionClass->getMethod($method);
54
-                $classProperties   = $reflectionClass->getDefaultProperties();
55
-                $skipLoginCheck    = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
56
-                $validationRules   = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
52
+				$reflectionClass   = new \ReflectionClass($controller);
53
+				$reflectionMethod  = $reflectionClass->getMethod($method);
54
+				$classProperties   = $reflectionClass->getDefaultProperties();
55
+				$skipLoginCheck    = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
56
+				$validationRules   = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
57 57
 
58
-                $this->processDocBlock($route, $reflectionMethod);
59
-                $this->getHeaders($route, $method, $skipLoginCheck);
60
-                $this->getPostData($route, $reflectionMethod, $validationRules);
58
+				$this->processDocBlock($route, $reflectionMethod);
59
+				$this->getHeaders($route, $method, $skipLoginCheck);
60
+				$this->getPostData($route, $reflectionMethod, $validationRules);
61 61
 
62
-                $route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']);
62
+				$route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']);
63 63
 
64
-                preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module);
65
-                $docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/v1/' . $module[1] . '/') - 1)][] = $route;
64
+				preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module);
65
+				$docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/v1/' . $module[1] . '/') - 1)][] = $route;
66 66
 
67
-                $this->getModels($classProperties['model'], $docData);
68
-            }
69
-        }
67
+				$this->getModels($classProperties['model'], $docData);
68
+			}
69
+		}
70 70
         
71
-        $docData['errors'] = $this->getErrors();
72
-        \File::put(app_path('Modules/V1/Core/Resources/api.json'), json_encode($docData));
73
-    }
71
+		$docData['errors'] = $this->getErrors();
72
+		\File::put(app_path('Modules/V1/Core/Resources/api.json'), json_encode($docData));
73
+	}
74 74
 
75
-    /**
76
-     * Get list of all registered routes.
77
-     * 
78
-     * @return collection
79
-     */
80
-    protected function getRoutes()
81
-    {
82
-        return collect(\Route::getRoutes())->map(function ($route) {
83
-            if (strpos($route->uri(), 'api/v') !== false) 
84
-            {
85
-                return [
86
-                    'method' => $route->methods()[0],
87
-                    'uri'    => $route->uri(),
88
-                    'action' => $route->getActionName(),
89
-                    'prefix' => $route->getPrefix()
90
-                ];
91
-            }
92
-            return false;
93
-        })->all();
94
-    }
75
+	/**
76
+	 * Get list of all registered routes.
77
+	 * 
78
+	 * @return collection
79
+	 */
80
+	protected function getRoutes()
81
+	{
82
+		return collect(\Route::getRoutes())->map(function ($route) {
83
+			if (strpos($route->uri(), 'api/v') !== false) 
84
+			{
85
+				return [
86
+					'method' => $route->methods()[0],
87
+					'uri'    => $route->uri(),
88
+					'action' => $route->getActionName(),
89
+					'prefix' => $route->getPrefix()
90
+				];
91
+			}
92
+			return false;
93
+		})->all();
94
+	}
95 95
 
96
-    /**
97
-     * Generate headers for the given route.
98
-     * 
99
-     * @param  array  &$route
100
-     * @param  string $method
101
-     * @param  array  $skipLoginCheck
102
-     * @return void
103
-     */
104
-    protected function getHeaders(&$route, $method, $skipLoginCheck)
105
-    {
106
-        $route['headers'] = [
107
-        'Accept'         => 'application/json',
108
-        'Content-Type'   => 'application/json',
109
-        'locale'         => 'The language of the returned data: ar, en or all.',
110
-        'time-zone-diff' => 'Timezone difference between UTC and Local Time',
111
-        ];
96
+	/**
97
+	 * Generate headers for the given route.
98
+	 * 
99
+	 * @param  array  &$route
100
+	 * @param  string $method
101
+	 * @param  array  $skipLoginCheck
102
+	 * @return void
103
+	 */
104
+	protected function getHeaders(&$route, $method, $skipLoginCheck)
105
+	{
106
+		$route['headers'] = [
107
+		'Accept'         => 'application/json',
108
+		'Content-Type'   => 'application/json',
109
+		'locale'         => 'The language of the returned data: ar, en or all.',
110
+		'time-zone-diff' => 'Timezone difference between UTC and Local Time',
111
+		];
112 112
 
113 113
 
114
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
115
-        {
116
-            $route['headers']['Authrization'] = 'Bearer {token}';
117
-        }
118
-    }
114
+		if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
115
+		{
116
+			$route['headers']['Authrization'] = 'Bearer {token}';
117
+		}
118
+	}
119 119
 
120
-    /**
121
-     * Generate description and params for the given route
122
-     * based on the docblock.
123
-     * 
124
-     * @param  array  &$route
125
-     * @param  object $reflectionMethod]
126
-     * @return void
127
-     */
128
-    protected function processDocBlock(&$route, $reflectionMethod)
129
-    {
130
-        $factory                 = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
131
-        $docblock                = $factory->create($reflectionMethod->getDocComment());
132
-        $route['description']    = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
133
-        $params                  = $docblock->getTagsByName('param');
134
-        $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName();
135
-        foreach ($params as $param) 
136
-        {
137
-            $name = $param->getVariableName();
138
-            if ($name !== 'request') 
139
-            {
140
-                $route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
141
-            }
142
-        }
143
-    }
120
+	/**
121
+	 * Generate description and params for the given route
122
+	 * based on the docblock.
123
+	 * 
124
+	 * @param  array  &$route
125
+	 * @param  object $reflectionMethod]
126
+	 * @return void
127
+	 */
128
+	protected function processDocBlock(&$route, $reflectionMethod)
129
+	{
130
+		$factory                 = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
131
+		$docblock                = $factory->create($reflectionMethod->getDocComment());
132
+		$route['description']    = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
133
+		$params                  = $docblock->getTagsByName('param');
134
+		$route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName();
135
+		foreach ($params as $param) 
136
+		{
137
+			$name = $param->getVariableName();
138
+			if ($name !== 'request') 
139
+			{
140
+				$route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
141
+			}
142
+		}
143
+	}
144 144
 
145
-    /**
146
-     * Generate post body for the given route.
147
-     * 
148
-     * @param  array  &$route
149
-     * @param  object $reflectionMethod
150
-     * @param  array  $validationRules
151
-     * @return void
152
-     */
153
-    protected function getPostData(&$route, $reflectionMethod, $validationRules)
154
-    {
155
-        if ($route['method'] == 'POST') 
156
-        {
157
-            $body = $this->getMethodBody($reflectionMethod);
145
+	/**
146
+	 * Generate post body for the given route.
147
+	 * 
148
+	 * @param  array  &$route
149
+	 * @param  object $reflectionMethod
150
+	 * @param  array  $validationRules
151
+	 * @return void
152
+	 */
153
+	protected function getPostData(&$route, $reflectionMethod, $validationRules)
154
+	{
155
+		if ($route['method'] == 'POST') 
156
+		{
157
+			$body = $this->getMethodBody($reflectionMethod);
158 158
 
159
-            preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
160
-            if (count($match)) 
161
-            {
162
-                if ($match[1] == '$this->validationRules')
163
-                {
164
-                    $route['body'] = $validationRules;
165
-                }
166
-                else
167
-                {
168
-                    $route['body'] = eval('return ' . str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]) . ';');
169
-                }
159
+			preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
160
+			if (count($match)) 
161
+			{
162
+				if ($match[1] == '$this->validationRules')
163
+				{
164
+					$route['body'] = $validationRules;
165
+				}
166
+				else
167
+				{
168
+					$route['body'] = eval('return ' . str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]) . ';');
169
+				}
170 170
 
171
-                foreach ($route['body'] as &$rule) 
172
-                {
173
-                    if(strpos($rule, 'unique'))
174
-                    {
175
-                        $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
176
-                    }
177
-                    elseif(strpos($rule, 'exists'))
178
-                    {
179
-                        $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
180
-                    }
181
-                }
182
-            }
183
-            else
184
-            {
185
-                $route['body'] = 'conditions';
186
-            }
187
-        }
188
-    }
171
+				foreach ($route['body'] as &$rule) 
172
+				{
173
+					if(strpos($rule, 'unique'))
174
+					{
175
+						$rule = substr($rule, 0, strpos($rule, 'unique') + 6);
176
+					}
177
+					elseif(strpos($rule, 'exists'))
178
+					{
179
+						$rule = substr($rule, 0, strpos($rule, 'exists') - 1);
180
+					}
181
+				}
182
+			}
183
+			else
184
+			{
185
+				$route['body'] = 'conditions';
186
+			}
187
+		}
188
+	}
189 189
 
190
-    /**
191
-     * Generate application errors.
192
-     * 
193
-     * @return array
194
-     */
195
-    protected function getErrors()
196
-    {
197
-        $errors          = [];
198
-        $reflectionClass = new \ReflectionClass('App\Modules\V1\Core\Utl\ErrorHandler');
199
-        foreach ($reflectionClass->getMethods() as $method) 
200
-        {
201
-            $methodName       = $method->getName();
202
-            $reflectionMethod = $reflectionClass->getMethod($methodName);
203
-            $body             = $this->getMethodBody($reflectionMethod);
190
+	/**
191
+	 * Generate application errors.
192
+	 * 
193
+	 * @return array
194
+	 */
195
+	protected function getErrors()
196
+	{
197
+		$errors          = [];
198
+		$reflectionClass = new \ReflectionClass('App\Modules\V1\Core\Utl\ErrorHandler');
199
+		foreach ($reflectionClass->getMethods() as $method) 
200
+		{
201
+			$methodName       = $method->getName();
202
+			$reflectionMethod = $reflectionClass->getMethod($methodName);
203
+			$body             = $this->getMethodBody($reflectionMethod);
204 204
 
205
-            preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
205
+			preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
206 206
 
207
-            if (count($match)) 
208
-            {
209
-                $errors[$match[1]][] = $methodName;
210
-            }
211
-        }
207
+			if (count($match)) 
208
+			{
209
+				$errors[$match[1]][] = $methodName;
210
+			}
211
+		}
212 212
 
213
-        return $errors;
214
-    }
213
+		return $errors;
214
+	}
215 215
 
216
-    /**
217
-     * Get the given method body code.
218
-     * 
219
-     * @param  object $reflectionMethod
220
-     * @return string
221
-     */
222
-    protected function getMethodBody($reflectionMethod)
223
-    {
224
-        $filename   = $reflectionMethod->getFileName();
225
-        $start_line = $reflectionMethod->getStartLine() - 1;
226
-        $end_line   = $reflectionMethod->getEndLine();
227
-        $length     = $end_line - $start_line;         
228
-        $source     = file($filename);
229
-        $body       = implode("", array_slice($source, $start_line, $length));
230
-        $body       = trim(preg_replace('/\s+/', '', $body));
216
+	/**
217
+	 * Get the given method body code.
218
+	 * 
219
+	 * @param  object $reflectionMethod
220
+	 * @return string
221
+	 */
222
+	protected function getMethodBody($reflectionMethod)
223
+	{
224
+		$filename   = $reflectionMethod->getFileName();
225
+		$start_line = $reflectionMethod->getStartLine() - 1;
226
+		$end_line   = $reflectionMethod->getEndLine();
227
+		$length     = $end_line - $start_line;         
228
+		$source     = file($filename);
229
+		$body       = implode("", array_slice($source, $start_line, $length));
230
+		$body       = trim(preg_replace('/\s+/', '', $body));
231 231
 
232
-        return $body;
233
-    }
232
+		return $body;
233
+	}
234 234
 
235
-    /**
236
-     * Get example object of all availble models.
237
-     * 
238
-     * @param  string $modelName
239
-     * @param  array  $docData
240
-     * @return string
241
-     */
242
-    protected function getModels($modelName, &$docData)
243
-    {
244
-        if ($modelName && ! array_key_exists($modelName, $docData['models'])) 
245
-        {
246
-            $modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
247
-            $model      = factory($modelClass)->make();
248
-            $modelArr   = $model->toArray();
235
+	/**
236
+	 * Get example object of all availble models.
237
+	 * 
238
+	 * @param  string $modelName
239
+	 * @param  array  $docData
240
+	 * @return string
241
+	 */
242
+	protected function getModels($modelName, &$docData)
243
+	{
244
+		if ($modelName && ! array_key_exists($modelName, $docData['models'])) 
245
+		{
246
+			$modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
247
+			$model      = factory($modelClass)->make();
248
+			$modelArr   = $model->toArray();
249 249
 
250
-            if ( $model->trans && ! $model->trans->count()) 
251
-            {
252
-                $modelArr['trans'] = [
253
-                    'en' => factory($modelClass . 'Translation')->make()->toArray()
254
-                ];
255
-            }
250
+			if ( $model->trans && ! $model->trans->count()) 
251
+			{
252
+				$modelArr['trans'] = [
253
+					'en' => factory($modelClass . 'Translation')->make()->toArray()
254
+				];
255
+			}
256 256
 
257
-            $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
258
-        }
259
-    }
257
+			$docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
258
+		}
259
+	}
260 260
 
261
-    /**
262
-     * Get the route response object type.
263
-     * 
264
-     * @param  string $modelName
265
-     * @param  string $method
266
-     * @param  string $returnDocBlock
267
-     * @return array
268
-     */
269
-    protected function getResponseObject($modelName, $method, $returnDocBlock)
270
-    {
271
-        $config    = \CoreConfig::getConfig();
272
-        $relations = array_key_exists($modelName, $config['relations']) ? array_key_exists($method, $config['relations'][$modelName]) ? $config['relations'][$modelName] : false : false;
273
-        $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName;
261
+	/**
262
+	 * Get the route response object type.
263
+	 * 
264
+	 * @param  string $modelName
265
+	 * @param  string $method
266
+	 * @param  string $returnDocBlock
267
+	 * @return array
268
+	 */
269
+	protected function getResponseObject($modelName, $method, $returnDocBlock)
270
+	{
271
+		$config    = \CoreConfig::getConfig();
272
+		$relations = array_key_exists($modelName, $config['relations']) ? array_key_exists($method, $config['relations'][$modelName]) ? $config['relations'][$modelName] : false : false;
273
+		$modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName;
274 274
 
275
-        return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
276
-    }
275
+		return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
276
+	}
277 277
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/BaseApiController.php 1 patch
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -6,307 +6,307 @@
 block discarded – undo
6 6
 
7 7
 class BaseApiController extends Controller
8 8
 {
9
-    /**
10
-     * The config implementation.
11
-     * 
12
-     * @var array
13
-     */
14
-    protected $config;
9
+	/**
10
+	 * The config implementation.
11
+	 * 
12
+	 * @var array
13
+	 */
14
+	protected $config;
15 15
 
16
-    /**
17
-     * The relations implementation.
18
-     * 
19
-     * @var array
20
-     */
21
-    protected $relations;
16
+	/**
17
+	 * The relations implementation.
18
+	 * 
19
+	 * @var array
20
+	 */
21
+	protected $relations;
22 22
 
23
-    /**
24
-     * The repo implementation.
25
-     * 
26
-     * @var object
27
-     */
28
-    protected $repo;
23
+	/**
24
+	 * The repo implementation.
25
+	 * 
26
+	 * @var object
27
+	 */
28
+	protected $repo;
29 29
 
30
-    public function __construct()
31
-    {        
32
-        $this->config              = \CoreConfig::getConfig();
33
-        $this->model               = property_exists($this, 'model') ? $this->model : false;
34
-        $this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
35
-        $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
36
-        $this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
37
-        $this->repo                = call_user_func_array("\Core::{$this->model}", []);
38
-        $route                     = explode('@',\Route::currentRouteAction())[1];
30
+	public function __construct()
31
+	{        
32
+		$this->config              = \CoreConfig::getConfig();
33
+		$this->model               = property_exists($this, 'model') ? $this->model : false;
34
+		$this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
35
+		$this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
36
+		$this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
37
+		$this->repo                = call_user_func_array("\Core::{$this->model}", []);
38
+		$route                     = explode('@',\Route::currentRouteAction())[1];
39 39
 
40
-        $this->checkPermission($route);
41
-        $this->setRelations($route);
42
-        $this->setSessions();
43
-    }
40
+		$this->checkPermission($route);
41
+		$this->setRelations($route);
42
+		$this->setSessions();
43
+	}
44 44
 
45
-    /**
46
-     * Fetch all records with relations from storage.
47
-     * 
48
-     * @param  string  $sortBy The name of the column to sort by.
49
-     * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
50
-     * @return \Illuminate\Http\Response
51
-     */
52
-    public function index($sortBy = 'created_at', $desc = 1) 
53
-    {
54
-        if ($this->repo)
55
-        {
56
-            return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200);
57
-        }
58
-    }
45
+	/**
46
+	 * Fetch all records with relations from storage.
47
+	 * 
48
+	 * @param  string  $sortBy The name of the column to sort by.
49
+	 * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
50
+	 * @return \Illuminate\Http\Response
51
+	 */
52
+	public function index($sortBy = 'created_at', $desc = 1) 
53
+	{
54
+		if ($this->repo)
55
+		{
56
+			return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200);
57
+		}
58
+	}
59 59
 
60
-    /**
61
-     * Fetch the single object with relations from storage.
62
-     * 
63
-     * @param  integer $id Id of the requested model.
64
-     * @return \Illuminate\Http\Response
65
-     */
66
-    public function find($id) 
67
-    {
68
-        if ($this->repo) 
69
-        {
70
-            return \Response::json($this->repo->find($id, $this->relations), 200);
71
-        }
72
-    }
60
+	/**
61
+	 * Fetch the single object with relations from storage.
62
+	 * 
63
+	 * @param  integer $id Id of the requested model.
64
+	 * @return \Illuminate\Http\Response
65
+	 */
66
+	public function find($id) 
67
+	{
68
+		if ($this->repo) 
69
+		{
70
+			return \Response::json($this->repo->find($id, $this->relations), 200);
71
+		}
72
+	}
73 73
 
74
-    /**
75
-     * Paginate all records with relations from storage
76
-     * that matche the given query.
77
-     * 
78
-     * @param  string  $query   The search text.
79
-     * @param  integer $perPage Number of rows per page default 15.
80
-     * @param  string  $sortBy  The name of the column to sort by.
81
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
82
-     * @return \Illuminate\Http\Response
83
-     */
84
-    public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
85
-    {
86
-        if ($this->repo) 
87
-        {
88
-            return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200);
89
-        }
90
-    }
74
+	/**
75
+	 * Paginate all records with relations from storage
76
+	 * that matche the given query.
77
+	 * 
78
+	 * @param  string  $query   The search text.
79
+	 * @param  integer $perPage Number of rows per page default 15.
80
+	 * @param  string  $sortBy  The name of the column to sort by.
81
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
82
+	 * @return \Illuminate\Http\Response
83
+	 */
84
+	public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
85
+	{
86
+		if ($this->repo) 
87
+		{
88
+			return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200);
89
+		}
90
+	}
91 91
 
92
-    /**
93
-     * Fetch records from the storage based on the given
94
-     * condition.
95
-     * 
96
-     * @param  \Illuminate\Http\Request  $request
97
-     * @param  string  $sortBy The name of the column to sort by.
98
-     * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
99
-     * @return \Illuminate\Http\Response
100
-     */
101
-    public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
102
-    {
103
-        if ($this->repo) 
104
-        {
105
-            return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200);
106
-        }
107
-    }
92
+	/**
93
+	 * Fetch records from the storage based on the given
94
+	 * condition.
95
+	 * 
96
+	 * @param  \Illuminate\Http\Request  $request
97
+	 * @param  string  $sortBy The name of the column to sort by.
98
+	 * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
99
+	 * @return \Illuminate\Http\Response
100
+	 */
101
+	public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
102
+	{
103
+		if ($this->repo) 
104
+		{
105
+			return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200);
106
+		}
107
+	}
108 108
 
109
-    /**
110
-     * Fetch the first record from the storage based on the given
111
-     * condition.
112
-     * 
113
-     * @param  \Illuminate\Http\Request  $request
114
-     * @return \Illuminate\Http\Response
115
-     */
116
-    public function first(Request $request) 
117
-    {
118
-        if ($this->repo) 
119
-        {
120
-            return \Response::json($this->repo->first($request->all(), $this->relations), 200);
121
-        }
122
-    }
109
+	/**
110
+	 * Fetch the first record from the storage based on the given
111
+	 * condition.
112
+	 * 
113
+	 * @param  \Illuminate\Http\Request  $request
114
+	 * @return \Illuminate\Http\Response
115
+	 */
116
+	public function first(Request $request) 
117
+	{
118
+		if ($this->repo) 
119
+		{
120
+			return \Response::json($this->repo->first($request->all(), $this->relations), 200);
121
+		}
122
+	}
123 123
 
124
-    /**
125
-     * Paginate all records with relations from storage.
126
-     * 
127
-     * @param  integer $perPage Number of rows per page default 15.
128
-     * @param  string  $sortBy  The name of the column to sort by.
129
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
130
-     * @return \Illuminate\Http\Response
131
-     */
132
-    public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
133
-    {
134
-        if ($this->repo) 
135
-        {
136
-            return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200);
137
-        }
138
-    }
124
+	/**
125
+	 * Paginate all records with relations from storage.
126
+	 * 
127
+	 * @param  integer $perPage Number of rows per page default 15.
128
+	 * @param  string  $sortBy  The name of the column to sort by.
129
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
130
+	 * @return \Illuminate\Http\Response
131
+	 */
132
+	public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
133
+	{
134
+		if ($this->repo) 
135
+		{
136
+			return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200);
137
+		}
138
+	}
139 139
 
140
-    /**
141
-     * Fetch all records with relations based on
142
-     * the given condition from storage in pages.
143
-     * 
144
-     * @param  \Illuminate\Http\Request  $request
145
-     * @param  integer $perPage Number of rows per page default 15.
146
-     * @param  string  $sortBy  The name of the column to sort by.
147
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
148
-     * @return \Illuminate\Http\Response
149
-     */
150
-    public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
151
-    {
152
-        if ($this->repo) 
153
-        {
154
-            return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200);
155
-        }
156
-    }
140
+	/**
141
+	 * Fetch all records with relations based on
142
+	 * the given condition from storage in pages.
143
+	 * 
144
+	 * @param  \Illuminate\Http\Request  $request
145
+	 * @param  integer $perPage Number of rows per page default 15.
146
+	 * @param  string  $sortBy  The name of the column to sort by.
147
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
148
+	 * @return \Illuminate\Http\Response
149
+	 */
150
+	public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
151
+	{
152
+		if ($this->repo) 
153
+		{
154
+			return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200);
155
+		}
156
+	}
157 157
 
158
-    /**
159
-     * Save the given model to storage.
160
-     * 
161
-     * @param  \Illuminate\Http\Request  $request
162
-     * @return \Illuminate\Http\Response
163
-     */
164
-    public function save(Request $request) 
165
-    {
166
-        foreach ($this->validationRules as &$rule) 
167
-        {
168
-            if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
169
-            {
170
-                $rule .= ',deleted_at,NULL';
171
-            }
158
+	/**
159
+	 * Save the given model to storage.
160
+	 * 
161
+	 * @param  \Illuminate\Http\Request  $request
162
+	 * @return \Illuminate\Http\Response
163
+	 */
164
+	public function save(Request $request) 
165
+	{
166
+		foreach ($this->validationRules as &$rule) 
167
+		{
168
+			if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
169
+			{
170
+				$rule .= ',deleted_at,NULL';
171
+			}
172 172
 
173
-            if ($request->has('id')) 
174
-            {
175
-                $rule = str_replace('{id}', $request->get('id'), $rule);
176
-            }
177
-            else
178
-            {
179
-                $rule = str_replace(',{id}', '', $rule);
180
-            }
181
-        }
173
+			if ($request->has('id')) 
174
+			{
175
+				$rule = str_replace('{id}', $request->get('id'), $rule);
176
+			}
177
+			else
178
+			{
179
+				$rule = str_replace(',{id}', '', $rule);
180
+			}
181
+		}
182 182
         
183
-        $this->validate($request, $this->validationRules);
183
+		$this->validate($request, $this->validationRules);
184 184
 
185
-        if ($this->repo) 
186
-        {
187
-            return \Response::json($this->repo->save($request->all()), 200);
188
-        }
189
-    }
185
+		if ($this->repo) 
186
+		{
187
+			return \Response::json($this->repo->save($request->all()), 200);
188
+		}
189
+	}
190 190
 
191
-    /**
192
-     * Delete by the given id from storage.
193
-     * 
194
-     * @param  integer $id Id of the deleted model.
195
-     * @return \Illuminate\Http\Response
196
-     */
197
-    public function delete($id) 
198
-    {
199
-        if ($this->repo) 
200
-        {
201
-            return \Response::json($this->repo->delete($id), 200);
202
-        }
203
-    }
191
+	/**
192
+	 * Delete by the given id from storage.
193
+	 * 
194
+	 * @param  integer $id Id of the deleted model.
195
+	 * @return \Illuminate\Http\Response
196
+	 */
197
+	public function delete($id) 
198
+	{
199
+		if ($this->repo) 
200
+		{
201
+			return \Response::json($this->repo->delete($id), 200);
202
+		}
203
+	}
204 204
 
205
-    /**
206
-     * Return the deleted models in pages based on the given conditions.
207
-     *
208
-     * @param  \Illuminate\Http\Request  $request
209
-     * @param  integer $perPage Number of rows per page default 15.
210
-     * @param  string  $sortBy  The name of the column to sort by.
211
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
212
-     * @return \Illuminate\Http\Response
213
-     */
214
-    public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
215
-    {
216
-        return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200);
217
-    }
205
+	/**
206
+	 * Return the deleted models in pages based on the given conditions.
207
+	 *
208
+	 * @param  \Illuminate\Http\Request  $request
209
+	 * @param  integer $perPage Number of rows per page default 15.
210
+	 * @param  string  $sortBy  The name of the column to sort by.
211
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
212
+	 * @return \Illuminate\Http\Response
213
+	 */
214
+	public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
215
+	{
216
+		return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200);
217
+	}
218 218
 
219
-    /**
220
-     * Restore the deleted model.
221
-     * 
222
-     * @param  integer $id Id of the restored model.
223
-     * @return \Illuminate\Http\Response
224
-     */
225
-    public function restore($id) 
226
-    {
227
-        if ($this->repo) 
228
-        {
229
-            return \Response::json($this->repo->restore($id), 200);
230
-        }
231
-    }
219
+	/**
220
+	 * Restore the deleted model.
221
+	 * 
222
+	 * @param  integer $id Id of the restored model.
223
+	 * @return \Illuminate\Http\Response
224
+	 */
225
+	public function restore($id) 
226
+	{
227
+		if ($this->repo) 
228
+		{
229
+			return \Response::json($this->repo->restore($id), 200);
230
+		}
231
+	}
232 232
 
233
-    /**
234
-     * Check if the logged in user can do the given permission.
235
-     * 
236
-     * @param  string $permission
237
-     * @return void
238
-     */
239
-    private function checkPermission($permission)
240
-    {   
241
-        \Auth::shouldUse('api');
242
-        $this->middleware('auth:api', ['except' => $this->skipLoginCheck]);
233
+	/**
234
+	 * Check if the logged in user can do the given permission.
235
+	 * 
236
+	 * @param  string $permission
237
+	 * @return void
238
+	 */
239
+	private function checkPermission($permission)
240
+	{   
241
+		\Auth::shouldUse('api');
242
+		$this->middleware('auth:api', ['except' => $this->skipLoginCheck]);
243 243
         
244
-        if ($user = \Auth::user()) 
245
-        {
246
-            $permission       = $permission !== 'index' ? $permission : 'list';
247
-            $isPasswordClient = $user->token()->client->password_client;
244
+		if ($user = \Auth::user()) 
245
+		{
246
+			$permission       = $permission !== 'index' ? $permission : 'list';
247
+			$isPasswordClient = $user->token()->client->password_client;
248 248
 
249
-            if ($user->blocked)
250
-            {
251
-                \ErrorHandler::userIsBlocked();
252
-            }
249
+			if ($user->blocked)
250
+			{
251
+				\ErrorHandler::userIsBlocked();
252
+			}
253 253
 
254
-            if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model)))
255
-            {}
256
-            elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) 
257
-            {}
258
-            else
259
-            {
254
+			if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model)))
255
+			{}
256
+			elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) 
257
+			{}
258
+			else
259
+			{
260 260
 
261
-                \ErrorHandler::noPermissions();
262
-            }
263
-        }
264
-    }
261
+				\ErrorHandler::noPermissions();
262
+			}
263
+		}
264
+	}
265 265
 
266
-    /**
267
-     * Set sessions based on the given headers in the request.
268
-     * 
269
-     * @return void
270
-     */
271
-    private function setSessions()
272
-    {
273
-        \Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
266
+	/**
267
+	 * Set sessions based on the given headers in the request.
268
+	 * 
269
+	 * @return void
270
+	 */
271
+	private function setSessions()
272
+	{
273
+		\Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
274 274
 
275
-        $locale = \Request::header('locale');
276
-        switch ($locale) 
277
-        {
278
-            case 'en':
279
-            \App::setLocale('en');
280
-            \Session::put('locale', 'en');
281
-            break;
275
+		$locale = \Request::header('locale');
276
+		switch ($locale) 
277
+		{
278
+			case 'en':
279
+			\App::setLocale('en');
280
+			\Session::put('locale', 'en');
281
+			break;
282 282
 
283
-            case 'ar':
284
-            \App::setLocale('ar');
285
-            \Session::put('locale', 'ar');
286
-            break;
283
+			case 'ar':
284
+			\App::setLocale('ar');
285
+			\Session::put('locale', 'ar');
286
+			break;
287 287
 
288
-            case 'all':
289
-            \App::setLocale('en');
290
-            \Session::put('locale', 'all');
291
-            break;
288
+			case 'all':
289
+			\App::setLocale('en');
290
+			\Session::put('locale', 'all');
291
+			break;
292 292
 
293
-            default:
294
-            \App::setLocale('en');
295
-            \Session::put('locale', 'en');
296
-            break;
297
-        }
298
-    }
293
+			default:
294
+			\App::setLocale('en');
295
+			\Session::put('locale', 'en');
296
+			break;
297
+		}
298
+	}
299 299
 
300
-    /**
301
-     * Set relation based on the called api.
302
-     * 
303
-     * @param  string $route
304
-     * @return void
305
-     */
306
-    private function setRelations($route)
307
-    {
308
-        $route           = $route !== 'index' ? $route : 'list';
309
-        $relations       = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
310
-        $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : [];
311
-    }
300
+	/**
301
+	 * Set relation based on the called api.
302
+	 * 
303
+	 * @param  string $route
304
+	 * @return void
305
+	 */
306
+	private function setRelations($route)
307
+	{
308
+		$route           = $route !== 'index' ? $route : 'list';
309
+		$relations       = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
310
+		$this->relations = $relations && isset($relations[$route]) ? $relations[$route] : [];
311
+	}
312 312
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Traits/Translatable.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -2,51 +2,51 @@
 block discarded – undo
2 2
 
3 3
 trait Translatable  
4 4
 {
5
-    /**
6
-     * Create a new model instance that is existing.
7
-     *
8
-     * @param  array  $attributes
9
-     * @param  string|null  $connection
10
-     * @return static
11
-     */
12
-    public function newFromBuilder($attributes = [], $connection = null)
13
-    {
14
-        $model = parent::newFromBuilder($attributes, $connection);
5
+	/**
6
+	 * Create a new model instance that is existing.
7
+	 *
8
+	 * @param  array  $attributes
9
+	 * @param  string|null  $connection
10
+	 * @return static
11
+	 */
12
+	public function newFromBuilder($attributes = [], $connection = null)
13
+	{
14
+		$model = parent::newFromBuilder($attributes, $connection);
15 15
 
16
-        foreach ($model->attributes AS $key => $value)
17
-        {
18
-            if (isset($this->translatable) && in_array($key, $this->translatable)) 
19
-            {
20
-                $model->$key = $this->getTranslatedAttribute($key, $value);
21
-            }
22
-        }
16
+		foreach ($model->attributes AS $key => $value)
17
+		{
18
+			if (isset($this->translatable) && in_array($key, $this->translatable)) 
19
+			{
20
+				$model->$key = $this->getTranslatedAttribute($key, $value);
21
+			}
22
+		}
23 23
 
24
-        return $model;
25
-    }
24
+		return $model;
25
+	}
26 26
 
27
-    /**
28
-     * Returns a translatable model attribute based on the application's locale settings.
29
-     *
30
-     * @param $key
31
-     * @param $values
32
-     * @return string
33
-     */
34
-    protected function getTranslatedAttribute($key, $values)
35
-    {
36
-        $values         = json_decode($values);
37
-        $primaryLocale  = \Session::get(\CoreConfig::getConfig()['var_names']['locale']);
38
-        $fallbackLocale = \CoreConfig::getConfig()['var_names']['locale_fallback'];
27
+	/**
28
+	 * Returns a translatable model attribute based on the application's locale settings.
29
+	 *
30
+	 * @param $key
31
+	 * @param $values
32
+	 * @return string
33
+	 */
34
+	protected function getTranslatedAttribute($key, $values)
35
+	{
36
+		$values         = json_decode($values);
37
+		$primaryLocale  = \Session::get(\CoreConfig::getConfig()['var_names']['locale']);
38
+		$fallbackLocale = \CoreConfig::getConfig()['var_names']['locale_fallback'];
39 39
 
40
-        if ($primaryLocale == 'all') 
41
-        {
42
-            return $values;
43
-        }
40
+		if ($primaryLocale == 'all') 
41
+		{
42
+			return $values;
43
+		}
44 44
 
45
-        if ( ! $primaryLocale || ! isset($values->$primaryLocale)) 
46
-        {
47
-            return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
48
-        }
45
+		if ( ! $primaryLocale || ! isset($values->$primaryLocale)) 
46
+		{
47
+			return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
48
+		}
49 49
 
50
-        return $primaryLocale == 'all' ? $values : $values->$primaryLocale;
51
-    }
50
+		return $primaryLocale == 'all' ? $values : $values->$primaryLocale;
51
+	}
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.