Completed
Push — master ( 2250ba...f4130d )
by Sherif
02:44
created
src/Modules/V1/Acl/Repositories/UserRepository.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@
 block discarded – undo
202 202
      * Reset the given user's password.
203 203
      *
204 204
      * @param  array  $credentials
205
-     * @return integer
205
+     * @return false|null
206 206
      */
207 207
     public function resetPassword($credentials)
208 208
     {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
      * @param  boolean $user
24 24
      * @return boolean
25 25
      */
26
-    public function can($nameOfPermission, $model, $user = false )
26
+    public function can($nameOfPermission, $model, $user = false)
27 27
     {       
28 28
         $user        = $user ?: \JWTAuth::parseToken()->authenticate();
29 29
         $permissions = [];
30
-        \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
30
+        \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function($permission) use (&$permissions, $model){
31 31
             $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32 32
         });
33 33
         
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function assignGroups($user_id, $group_ids)
57 57
     {
58
-        \DB::transaction(function () use ($user_id, $group_ids) {
58
+        \DB::transaction(function() use ($user_id, $group_ids) {
59 59
             $user = \Core::users()->find($user_id);
60 60
             $user->groups()->detach();
61 61
             $user->groups()->attach($group_ids);
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public function sendReset($email)
189 189
     {
190
-        $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
190
+        $response = \Password::sendResetLink($email, function(\Illuminate\Mail\Message $message) {
191 191
             $message->subject('Your Password Reset Link');
192 192
         });
193 193
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     public function resetPassword($credentials)
208 208
     {
209 209
         $token    = false;
210
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
210
+        $response = \Password::reset($credentials, function($user, $password) use (&$token) {
211 211
             $user->password = $password;
212 212
             $user->save();
213 213
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -76,24 +76,19 @@  discard block
 block discarded – undo
76 76
         if ( ! $user = \Core::users()->first(['email' => $credentials['email']])) 
77 77
         {
78 78
             \ErrorHandler::loginFailed();
79
-        }
80
-        else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
79
+        } else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
81 80
         {
82 81
             \ErrorHandler::loginFailed();
83
-        }
84
-        else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
82
+        } else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
85 83
         {
86 84
             \ErrorHandler::loginFailed();
87
-        }
88
-        else if ($user->blocked)
85
+        } else if ($user->blocked)
89 86
         {
90 87
             \ErrorHandler::userIsBlocked();
91
-        }
92
-        else if ($token = \JWTAuth::attempt($credentials))
88
+        } else if ($token = \JWTAuth::attempt($credentials))
93 89
         {
94 90
             return $token;
95
-        }
96
-        else
91
+        } else
97 92
         {
98 93
             \ErrorHandler::loginFailed();
99 94
         }
@@ -135,12 +130,10 @@  discard block
 block discarded – undo
135 130
         if ( ! $this->hasGroup('Admin'))
136 131
         {
137 132
             \ErrorHandler::noPermissions();
138
-        }
139
-        else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
133
+        } else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
140 134
         {
141 135
             \ErrorHandler::noPermissions();
142
-        }
143
-        else if ($user->groups->lists('name')->search('Admin', true) !== false) 
136
+        } else if ($user->groups->lists('name')->search('Admin', true) !== false) 
144 137
         {
145 138
             \ErrorHandler::noPermissions();
146 139
         }
Please login to merge, or discard this patch.
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -4,232 +4,232 @@
 block discarded – undo
4 4
 
5 5
 class UserRepository extends AbstractRepository
6 6
 {
7
-    /**
8
-     * Return the model full namespace.
9
-     * 
10
-     * @return string
11
-     */
12
-    protected function getModel()
13
-    {
14
-        return 'App\Modules\V1\Acl\AclUser';
15
-    }
16
-
17
-    /**
18
-     * Check if the logged in user or the given user 
19
-     * has the given permissions on the given model.
20
-     * 
21
-     * @param  string  $nameOfPermission
22
-     * @param  string  $model            
23
-     * @param  boolean $user
24
-     * @return boolean
25
-     */
26
-    public function can($nameOfPermission, $model, $user = false )
27
-    {       
28
-        $user        = $user ?: \JWTAuth::parseToken()->authenticate();
29
-        $permissions = [];
30
-        \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
31
-            $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32
-        });
7
+	/**
8
+	 * Return the model full namespace.
9
+	 * 
10
+	 * @return string
11
+	 */
12
+	protected function getModel()
13
+	{
14
+		return 'App\Modules\V1\Acl\AclUser';
15
+	}
16
+
17
+	/**
18
+	 * Check if the logged in user or the given user 
19
+	 * has the given permissions on the given model.
20
+	 * 
21
+	 * @param  string  $nameOfPermission
22
+	 * @param  string  $model            
23
+	 * @param  boolean $user
24
+	 * @return boolean
25
+	 */
26
+	public function can($nameOfPermission, $model, $user = false )
27
+	{       
28
+		$user        = $user ?: \JWTAuth::parseToken()->authenticate();
29
+		$permissions = [];
30
+		\Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
31
+			$permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32
+		});
33 33
         
34
-        return in_array($nameOfPermission, $permissions);
35
-    }
36
-
37
-    /**
38
-     * Check if the logged in user has the given group.
39
-     * 
40
-     * @param  string  $groupName
41
-     * @return boolean
42
-     */
43
-    public function hasGroup($groupName)
44
-    {
45
-        $groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
46
-        return $groups->lists('name')->search($groupName, true) === false ? false : true;
47
-    }
48
-
49
-    /**
50
-     * Assign the given group ids to the given user.
51
-     * 
52
-     * @param  integer $user_id    
53
-     * @param  array   $group_ids
54
-     * @return object
55
-     */
56
-    public function assignGroups($user_id, $group_ids)
57
-    {
58
-        \DB::transaction(function () use ($user_id, $group_ids) {
59
-            $user = \Core::users()->find($user_id);
60
-            $user->groups()->detach();
61
-            $user->groups()->attach($group_ids);
62
-        });
63
-
64
-        return \Core::users()->find($user_id);
65
-    }
66
-
67
-    /**
68
-     * Handle a login request to the application.
69
-     * 
70
-     * @param  array   $credentials    
71
-     * @param  boolean $adminLogin
72
-     * @return string
73
-     */
74
-    public function login($credentials, $adminLogin = false)
75
-    {
76
-        if ( ! $user = \Core::users()->first(['email' => $credentials['email']])) 
77
-        {
78
-            \ErrorHandler::loginFailed();
79
-        }
80
-        else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
81
-        {
82
-            \ErrorHandler::loginFailed();
83
-        }
84
-        else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
85
-        {
86
-            \ErrorHandler::loginFailed();
87
-        }
88
-        else if ($user->blocked)
89
-        {
90
-            \ErrorHandler::userIsBlocked();
91
-        }
92
-        else if ($token = \JWTAuth::attempt($credentials))
93
-        {
94
-            return ['token' => $token];
95
-        }
96
-        else
97
-        {
98
-            \ErrorHandler::loginFailed();
99
-        }
100
-    }
101
-
102
-    /**
103
-     * Handle a registration request.
104
-     * 
105
-     * @param  array $credentials
106
-     * @return string
107
-     */
108
-    public function register($credentials)
109
-    {
110
-        $user = \Core::users()->model->create($credentials);
111
-        $this->assignGroups($user->id, \Core::groups()->model->where('name', 'User')->select('id')->lists('id')->toArray());
112
-
113
-        return ['token' => \JWTAuth::fromUser($user)];
114
-    }
115
-
116
-    /**
117
-     * Logout the user.
118
-     * 
119
-     * @return boolean
120
-     */
121
-    public function logout()
122
-    {
123
-        return \JWTAuth::invalidate(\JWTAuth::getToken());
124
-    }
125
-
126
-    /**
127
-     * Block the user.
128
-     *
129
-     * @param  integer $user_id
130
-     * @return object
131
-     */
132
-    public function block($user_id)
133
-    {
134
-        if ( ! $user = \Core::users()->find($user_id)) 
135
-        {
136
-            \ErrorHandler::notFound('user');
137
-        }
138
-        if ( ! $this->hasGroup('Admin'))
139
-        {
140
-            \ErrorHandler::noPermissions();
141
-        }
142
-        else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
143
-        {
144
-            \ErrorHandler::noPermissions();
145
-        }
146
-        else if ($user->groups->lists('name')->search('Admin', true) !== false) 
147
-        {
148
-            \ErrorHandler::noPermissions();
149
-        }
150
-
151
-        $user->blocked = 1;
152
-        $user->save();
34
+		return in_array($nameOfPermission, $permissions);
35
+	}
36
+
37
+	/**
38
+	 * Check if the logged in user has the given group.
39
+	 * 
40
+	 * @param  string  $groupName
41
+	 * @return boolean
42
+	 */
43
+	public function hasGroup($groupName)
44
+	{
45
+		$groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
46
+		return $groups->lists('name')->search($groupName, true) === false ? false : true;
47
+	}
48
+
49
+	/**
50
+	 * Assign the given group ids to the given user.
51
+	 * 
52
+	 * @param  integer $user_id    
53
+	 * @param  array   $group_ids
54
+	 * @return object
55
+	 */
56
+	public function assignGroups($user_id, $group_ids)
57
+	{
58
+		\DB::transaction(function () use ($user_id, $group_ids) {
59
+			$user = \Core::users()->find($user_id);
60
+			$user->groups()->detach();
61
+			$user->groups()->attach($group_ids);
62
+		});
63
+
64
+		return \Core::users()->find($user_id);
65
+	}
66
+
67
+	/**
68
+	 * Handle a login request to the application.
69
+	 * 
70
+	 * @param  array   $credentials    
71
+	 * @param  boolean $adminLogin
72
+	 * @return string
73
+	 */
74
+	public function login($credentials, $adminLogin = false)
75
+	{
76
+		if ( ! $user = \Core::users()->first(['email' => $credentials['email']])) 
77
+		{
78
+			\ErrorHandler::loginFailed();
79
+		}
80
+		else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
81
+		{
82
+			\ErrorHandler::loginFailed();
83
+		}
84
+		else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
85
+		{
86
+			\ErrorHandler::loginFailed();
87
+		}
88
+		else if ($user->blocked)
89
+		{
90
+			\ErrorHandler::userIsBlocked();
91
+		}
92
+		else if ($token = \JWTAuth::attempt($credentials))
93
+		{
94
+			return ['token' => $token];
95
+		}
96
+		else
97
+		{
98
+			\ErrorHandler::loginFailed();
99
+		}
100
+	}
101
+
102
+	/**
103
+	 * Handle a registration request.
104
+	 * 
105
+	 * @param  array $credentials
106
+	 * @return string
107
+	 */
108
+	public function register($credentials)
109
+	{
110
+		$user = \Core::users()->model->create($credentials);
111
+		$this->assignGroups($user->id, \Core::groups()->model->where('name', 'User')->select('id')->lists('id')->toArray());
112
+
113
+		return ['token' => \JWTAuth::fromUser($user)];
114
+	}
115
+
116
+	/**
117
+	 * Logout the user.
118
+	 * 
119
+	 * @return boolean
120
+	 */
121
+	public function logout()
122
+	{
123
+		return \JWTAuth::invalidate(\JWTAuth::getToken());
124
+	}
125
+
126
+	/**
127
+	 * Block the user.
128
+	 *
129
+	 * @param  integer $user_id
130
+	 * @return object
131
+	 */
132
+	public function block($user_id)
133
+	{
134
+		if ( ! $user = \Core::users()->find($user_id)) 
135
+		{
136
+			\ErrorHandler::notFound('user');
137
+		}
138
+		if ( ! $this->hasGroup('Admin'))
139
+		{
140
+			\ErrorHandler::noPermissions();
141
+		}
142
+		else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
143
+		{
144
+			\ErrorHandler::noPermissions();
145
+		}
146
+		else if ($user->groups->lists('name')->search('Admin', true) !== false) 
147
+		{
148
+			\ErrorHandler::noPermissions();
149
+		}
150
+
151
+		$user->blocked = 1;
152
+		$user->save();
153 153
         
154
-        return $user;
155
-    }
156
-
157
-    /**
158
-     * Unblock the user.
159
-     *
160
-     * @param  integer $user_id
161
-     * @return object
162
-     */
163
-    public function unblock($user_id)
164
-    {
165
-        if ( ! $this->hasGroup('Admin'))
166
-        {
167
-            \ErrorHandler::noPermissions();
168
-        }
169
-
170
-        $user          = \Core::users()->find($user_id);
171
-        $user->blocked = 0;
172
-        $user->save();
173
-
174
-        return $user;
175
-    }
176
-
177
-    /**
178
-     * Send a reset link to the given user.
179
-     *
180
-     * @param  string  $url
181
-     * @param  string  $email
182
-     * @return void
183
-     */
184
-    public function sendReset($email, $url)
185
-    {
186
-        view()->composer('auth.emails.password', function($view) use ($url) {
187
-            $view->with(['url' => $url]);
188
-        });
189
-
190
-        $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
191
-            $message->subject('Your Password Reset Link');
192
-        });
193
-
194
-        switch ($response) 
195
-        {
196
-            case \Password::INVALID_USER:
197
-                \ErrorHandler::notFound('email');
198
-        }
199
-    }
200
-
201
-    /**
202
-     * Reset the given user's password.
203
-     *
204
-     * @param  array  $credentials
205
-     * @return integer
206
-     */
207
-    public function resetPassword($credentials)
208
-    {
209
-        $token    = false;
210
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
211
-            $user->password = bcrypt($password);
212
-            $user->save();
213
-
214
-            $token = \JWTAuth::fromUser($user);
215
-        });
216
-
217
-
218
-        switch ($response) {
219
-            case \Password::PASSWORD_RESET:
220
-                return $token;
154
+		return $user;
155
+	}
156
+
157
+	/**
158
+	 * Unblock the user.
159
+	 *
160
+	 * @param  integer $user_id
161
+	 * @return object
162
+	 */
163
+	public function unblock($user_id)
164
+	{
165
+		if ( ! $this->hasGroup('Admin'))
166
+		{
167
+			\ErrorHandler::noPermissions();
168
+		}
169
+
170
+		$user          = \Core::users()->find($user_id);
171
+		$user->blocked = 0;
172
+		$user->save();
173
+
174
+		return $user;
175
+	}
176
+
177
+	/**
178
+	 * Send a reset link to the given user.
179
+	 *
180
+	 * @param  string  $url
181
+	 * @param  string  $email
182
+	 * @return void
183
+	 */
184
+	public function sendReset($email, $url)
185
+	{
186
+		view()->composer('auth.emails.password', function($view) use ($url) {
187
+			$view->with(['url' => $url]);
188
+		});
189
+
190
+		$response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
191
+			$message->subject('Your Password Reset Link');
192
+		});
193
+
194
+		switch ($response) 
195
+		{
196
+			case \Password::INVALID_USER:
197
+				\ErrorHandler::notFound('email');
198
+		}
199
+	}
200
+
201
+	/**
202
+	 * Reset the given user's password.
203
+	 *
204
+	 * @param  array  $credentials
205
+	 * @return integer
206
+	 */
207
+	public function resetPassword($credentials)
208
+	{
209
+		$token    = false;
210
+		$response = \Password::reset($credentials, function ($user, $password) use (&$token) {
211
+			$user->password = bcrypt($password);
212
+			$user->save();
213
+
214
+			$token = \JWTAuth::fromUser($user);
215
+		});
216
+
217
+
218
+		switch ($response) {
219
+			case \Password::PASSWORD_RESET:
220
+				return $token;
221 221
                 
222
-            case \Password::INVALID_TOKEN:
223
-                \ErrorHandler::invalidResetToken('token');
222
+			case \Password::INVALID_TOKEN:
223
+				\ErrorHandler::invalidResetToken('token');
224 224
 
225
-            case \Password::INVALID_PASSWORD:
226
-                \ErrorHandler::invalidResetPassword('email');
225
+			case \Password::INVALID_PASSWORD:
226
+				\ErrorHandler::invalidResetPassword('email');
227 227
 
228
-            case \Password::INVALID_USER:
229
-                \ErrorHandler::notFound('user');
228
+			case \Password::INVALID_USER:
229
+				\ErrorHandler::notFound('user');
230 230
 
231
-            default:
232
-                \ErrorHandler::generalError();
233
-        }
234
-    }
231
+			default:
232
+				\ErrorHandler::generalError();
233
+		}
234
+	}
235 235
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Utl/ErrorHandler.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -2,81 +2,81 @@
 block discarded – undo
2 2
 
3 3
 class ErrorHandler
4 4
 {
5
-    public function unAuthorized()
6
-    {
7
-        $error = ['status' => 401, 'message' => 'Please login before any action'];
8
-        abort($error['status'], $error['message']);
9
-    }
5
+	public function unAuthorized()
6
+	{
7
+		$error = ['status' => 401, 'message' => 'Please login before any action'];
8
+		abort($error['status'], $error['message']);
9
+	}
10 10
 
11
-    public function tokenExpired()
12
-    {
13
-        $error = ['status' => 403, 'message' => 'Login token expired'];
14
-        abort($error['status'], $error['message']);
15
-    }
11
+	public function tokenExpired()
12
+	{
13
+		$error = ['status' => 403, 'message' => 'Login token expired'];
14
+		abort($error['status'], $error['message']);
15
+	}
16 16
 
17
-     public function noPermissions()
18
-    {
19
-        $error = ['status' => 403, 'message' => 'No permissions'];
20
-        abort($error['status'], $error['message']);
21
-    }
17
+	 public function noPermissions()
18
+	{
19
+		$error = ['status' => 403, 'message' => 'No permissions'];
20
+		abort($error['status'], $error['message']);
21
+	}
22 22
 
23
-    public function loginFailed()
24
-    {
25
-        $error = ['status' => 400, 'message' => 'Wrong mail or password'];
26
-        abort($error['status'], $error['message']);
27
-    }
23
+	public function loginFailed()
24
+	{
25
+		$error = ['status' => 400, 'message' => 'Wrong mail or password'];
26
+		abort($error['status'], $error['message']);
27
+	}
28 28
 
29
-    public function redisNotRunning()
30
-    {
31
-        $error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
32
-        abort($error['status'], $error['message']);
33
-    }
29
+	public function redisNotRunning()
30
+	{
31
+		$error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
32
+		abort($error['status'], $error['message']);
33
+	}
34 34
 
35
-    public function dbQueryError()
36
-    {
37
-        $error = ['status' => 400, 'message' => 'Please check the given inputes'];
38
-        abort($error['status'], $error['message']);
39
-    }
35
+	public function dbQueryError()
36
+	{
37
+		$error = ['status' => 400, 'message' => 'Please check the given inputes'];
38
+		abort($error['status'], $error['message']);
39
+	}
40 40
 
41
-    public function cannotCreateSetting()
42
-    {
43
-        $error = ['status' => 400, 'message' => 'Can\'t create setting'];
44
-        abort($error['status'], $error['message']);
45
-    }
41
+	public function cannotCreateSetting()
42
+	{
43
+		$error = ['status' => 400, 'message' => 'Can\'t create setting'];
44
+		abort($error['status'], $error['message']);
45
+	}
46 46
 
47
-    public function cannotUpdateSettingKey()
48
-    {
49
-        $error = ['status' => 400, 'message' => 'Can\'t update setting key'];
50
-        abort($error['status'], $error['message']);
51
-    }
47
+	public function cannotUpdateSettingKey()
48
+	{
49
+		$error = ['status' => 400, 'message' => 'Can\'t update setting key'];
50
+		abort($error['status'], $error['message']);
51
+	}
52 52
 
53
-    public function userIsBlocked()
54
-    {
55
-        $error = ['status' => 403, 'message' => 'You have been blocked'];
56
-        abort($error['status'], $error['message']);
57
-    }
53
+	public function userIsBlocked()
54
+	{
55
+		$error = ['status' => 403, 'message' => 'You have been blocked'];
56
+		abort($error['status'], $error['message']);
57
+	}
58 58
 
59
-    public function invalidResetToken()
60
-    {
61
-        $error = ['status' => 400, 'message' => 'Reset password token is invalid'];
62
-        abort($error['status'], $error['message']);
63
-    }
59
+	public function invalidResetToken()
60
+	{
61
+		$error = ['status' => 400, 'message' => 'Reset password token is invalid'];
62
+		abort($error['status'], $error['message']);
63
+	}
64 64
 
65
-    public function invalidResetPassword()
66
-    {
67
-        $error = ['status' => 400, 'message' => 'Reset password is invalid'];
68
-        abort($error['status'], $error['message']);
69
-    }
65
+	public function invalidResetPassword()
66
+	{
67
+		$error = ['status' => 400, 'message' => 'Reset password is invalid'];
68
+		abort($error['status'], $error['message']);
69
+	}
70 70
 
71
-    public function notFound($text)
72
-    {
73
-        $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
74
-        abort($error['status'], $error['message']);
75
-    }
71
+	public function notFound($text)
72
+	{
73
+		$error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
74
+		abort($error['status'], $error['message']);
75
+	}
76 76
 
77
-    public function generalError()
78
-    {
79
-        $error = ['status' => 404, 'message' => 'Something went wrong'];
80
-        abort($error['status'], $error['message']);
81
-    }
77
+	public function generalError()
78
+	{
79
+		$error = ['status' => 404, 'message' => 'Something went wrong'];
80
+		abort($error['status'], $error['message']);
81
+	}
82 82
 }
83 83
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
 
71 71
     public function notFound($text)
72 72
     {
73
-        $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
73
+        $error = ['status' => 404, 'message' => 'The requested '.$text.' not found'];
74 74
         abort($error['status'], $error['message']);
75 75
     }
76 76
 
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Http/Controllers/UsersController.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * to preform actions like (add, edit ... etc).
13 13
      * @var string
14 14
      */
15
-    protected $model               = 'users';
15
+    protected $model = 'users';
16 16
 
17 17
     /**
18 18
      * List of all route actions that the base api controller
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
      * will skip login check for them.
27 27
      * @var array
28 28
      */
29
-    protected $skipLoginCheck      = ['login', 'register', 'sendreset', 'resetpassword'];
29
+    protected $skipLoginCheck = ['login', 'register', 'sendreset', 'resetpassword'];
30 30
 
31 31
     /**
32 32
      * The validations rules used by the base api controller
33 33
      * to check before add.
34 34
      * @var array
35 35
      */
36
-    protected $validationRules     = [
36
+    protected $validationRules = [
37 37
     'email'    => 'required|email|unique:users,email,{id}',
38 38
     'password' => 'min:6'
39 39
     ];
Please login to merge, or discard this patch.
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,157 +7,157 @@
 block discarded – undo
7 7
 
8 8
 class UsersController extends BaseApiController
9 9
 {
10
-    /**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model               = 'users';
16
-
17
-    /**
18
-     * List of all route actions that the base api controller
19
-     * will skip permissions check for them.
20
-     * @var array
21
-     */
22
-    protected $skipPermissionCheck = ['account', 'logout', 'sendreset'];
23
-
24
-    /**
25
-     * List of all route actions that the base api controller
26
-     * will skip login check for them.
27
-     * @var array
28
-     */
29
-    protected $skipLoginCheck      = ['login', 'register', 'sendreset', 'resetpassword'];
30
-
31
-    /**
32
-     * The validations rules used by the base api controller
33
-     * to check before add.
34
-     * @var array
35
-     */
36
-    protected $validationRules     = [
37
-    'email'    => 'required|email|unique:users,email,{id}',
38
-    'password' => 'min:6'
39
-    ];
40
-
41
-    /**
42
-     * Return the logged in user account.
43
-     * 
44
-     * @return \Illuminate\Http\Response
45
-     */
46
-    public function account()
47
-    {
48
-       $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
49
-       return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200);
50
-    }
51
-
52
-    /**
53
-     * Block the user.
54
-     *
55
-     * @param  integer  $id
56
-     * @return \Illuminate\Http\Response
57
-     */
58
-    public function block($id)
59
-    {
60
-        return \Response::json(\Core::users()->block($id), 200);
61
-    }
62
-
63
-    /**
64
-     * Unblock the user.
65
-     *
66
-     * @param  integer  $id
67
-     * @return \Illuminate\Http\Response
68
-     */
69
-    public function unblock($id)
70
-    {
71
-        return \Response::json(\Core::users()->unblock($id), 200);
72
-    }
73
-
74
-    /**
75
-     * Logout the user.
76
-     * 
77
-     * @return \Illuminate\Http\Response
78
-     */
79
-    public function logout()
80
-    {
81
-        return \Response::json(\Core::users()->logout(), 200);
82
-    }
83
-
84
-    /**
85
-     * Handle a registration request.
86
-     *
87
-     * @param  \Illuminate\Http\Request  $request
88
-     * @return \Illuminate\Http\Response
89
-     */
90
-    public function register(Request $request)
91
-    {
92
-        $this->validate($request, [
93
-            'email'    => 'required|email|unique:users,email,{id}', 
94
-            'password' => 'required|min:6'
95
-            ]);
96
-
97
-        return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
98
-    }
99
-
100
-    /**
101
-     * Handle a login request of the none admin to the application.
102
-     *
103
-     * @param  \Illuminate\Http\Request  $request
104
-     * @return \Illuminate\Http\Response
105
-     */
106
-    public function login(Request $request)
107
-    {
108
-        $this->validate($request, [
109
-            'email'    => 'required|email', 
110
-            'password' => 'required|min:6',
111
-            'admin'    => 'boolean'
112
-            ]);
113
-
114
-        return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
115
-    }
116
-
117
-    /**
118
-     * Handle an assign groups to user request.
119
-     *
120
-     * @param  \Illuminate\Http\Request  $request
121
-     * @return \Illuminate\Http\Response
122
-     */
123
-    public function assigngroups(Request $request)
124
-    {
125
-        $this->validate($request, [
126
-            'group_ids' => 'required|exists:groups,id', 
127
-            'user_id'   => 'required|exists:users,id'
128
-            ]);
129
-
130
-        return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
131
-    }
132
-
133
-    /**
134
-     * Send a reset link to the given user.
135
-     *
136
-     * @param  \Illuminate\Http\Request  $request
137
-     * @return \Illuminate\Http\Response
138
-     */
139
-    public function sendreset(Request $request)
140
-    {
141
-        $this->validate($request, ['email' => 'required|email', 'url' => 'required|url']);
142
-
143
-        return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200);
144
-    }
145
-
146
-    /**
147
-     * Reset the given user's password.
148
-     *
149
-     * @param  \Illuminate\Http\Request  $request
150
-     * @return \Illuminate\Http\Response
151
-     */
152
-    public function resetpassword(Request $request)
153
-    {
154
-        $this->validate($request, [
155
-            'token'                 => 'required',
156
-            'email'                 => 'required|email',
157
-            'password'              => 'required|confirmed|min:6',
158
-            'password_confirmation' => 'required',
159
-        ]);
160
-
161
-        return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
162
-    }
10
+	/**
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model               = 'users';
16
+
17
+	/**
18
+	 * List of all route actions that the base api controller
19
+	 * will skip permissions check for them.
20
+	 * @var array
21
+	 */
22
+	protected $skipPermissionCheck = ['account', 'logout', 'sendreset'];
23
+
24
+	/**
25
+	 * List of all route actions that the base api controller
26
+	 * will skip login check for them.
27
+	 * @var array
28
+	 */
29
+	protected $skipLoginCheck      = ['login', 'register', 'sendreset', 'resetpassword'];
30
+
31
+	/**
32
+	 * The validations rules used by the base api controller
33
+	 * to check before add.
34
+	 * @var array
35
+	 */
36
+	protected $validationRules     = [
37
+	'email'    => 'required|email|unique:users,email,{id}',
38
+	'password' => 'min:6'
39
+	];
40
+
41
+	/**
42
+	 * Return the logged in user account.
43
+	 * 
44
+	 * @return \Illuminate\Http\Response
45
+	 */
46
+	public function account()
47
+	{
48
+	   $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
49
+	   return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200);
50
+	}
51
+
52
+	/**
53
+	 * Block the user.
54
+	 *
55
+	 * @param  integer  $id
56
+	 * @return \Illuminate\Http\Response
57
+	 */
58
+	public function block($id)
59
+	{
60
+		return \Response::json(\Core::users()->block($id), 200);
61
+	}
62
+
63
+	/**
64
+	 * Unblock the user.
65
+	 *
66
+	 * @param  integer  $id
67
+	 * @return \Illuminate\Http\Response
68
+	 */
69
+	public function unblock($id)
70
+	{
71
+		return \Response::json(\Core::users()->unblock($id), 200);
72
+	}
73
+
74
+	/**
75
+	 * Logout the user.
76
+	 * 
77
+	 * @return \Illuminate\Http\Response
78
+	 */
79
+	public function logout()
80
+	{
81
+		return \Response::json(\Core::users()->logout(), 200);
82
+	}
83
+
84
+	/**
85
+	 * Handle a registration request.
86
+	 *
87
+	 * @param  \Illuminate\Http\Request  $request
88
+	 * @return \Illuminate\Http\Response
89
+	 */
90
+	public function register(Request $request)
91
+	{
92
+		$this->validate($request, [
93
+			'email'    => 'required|email|unique:users,email,{id}', 
94
+			'password' => 'required|min:6'
95
+			]);
96
+
97
+		return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
98
+	}
99
+
100
+	/**
101
+	 * Handle a login request of the none admin to the application.
102
+	 *
103
+	 * @param  \Illuminate\Http\Request  $request
104
+	 * @return \Illuminate\Http\Response
105
+	 */
106
+	public function login(Request $request)
107
+	{
108
+		$this->validate($request, [
109
+			'email'    => 'required|email', 
110
+			'password' => 'required|min:6',
111
+			'admin'    => 'boolean'
112
+			]);
113
+
114
+		return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
115
+	}
116
+
117
+	/**
118
+	 * Handle an assign groups to user request.
119
+	 *
120
+	 * @param  \Illuminate\Http\Request  $request
121
+	 * @return \Illuminate\Http\Response
122
+	 */
123
+	public function assigngroups(Request $request)
124
+	{
125
+		$this->validate($request, [
126
+			'group_ids' => 'required|exists:groups,id', 
127
+			'user_id'   => 'required|exists:users,id'
128
+			]);
129
+
130
+		return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
131
+	}
132
+
133
+	/**
134
+	 * Send a reset link to the given user.
135
+	 *
136
+	 * @param  \Illuminate\Http\Request  $request
137
+	 * @return \Illuminate\Http\Response
138
+	 */
139
+	public function sendreset(Request $request)
140
+	{
141
+		$this->validate($request, ['email' => 'required|email', 'url' => 'required|url']);
142
+
143
+		return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200);
144
+	}
145
+
146
+	/**
147
+	 * Reset the given user's password.
148
+	 *
149
+	 * @param  \Illuminate\Http\Request  $request
150
+	 * @return \Illuminate\Http\Response
151
+	 */
152
+	public function resetpassword(Request $request)
153
+	{
154
+		$this->validate($request, [
155
+			'token'                 => 'required',
156
+			'email'                 => 'required|email',
157
+			'password'              => 'required|confirmed|min:6',
158
+			'password_confirmation' => 'required',
159
+		]);
160
+
161
+		return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
162
+	}
163 163
 }
Please login to merge, or discard this patch.
Modules/V1/Acl/Database/Migrations/2015_12_20_124154_password_resets.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -5,27 +5,27 @@
 block discarded – undo
5 5
 
6 6
 class PasswordResets extends Migration
7 7
 {
8
-    /**
9
-     * Run the migrations.
10
-     *
11
-     * @return void
12
-     */
13
-    public function up()
14
-    {
15
-        Schema::create('password_resets', function (Blueprint $table) {
16
-            $table->string('email')->index();
17
-            $table->string('token')->index();
18
-            $table->timestamp('created_at');
19
-        });
20
-    }
8
+	/**
9
+	 * Run the migrations.
10
+	 *
11
+	 * @return void
12
+	 */
13
+	public function up()
14
+	{
15
+		Schema::create('password_resets', function (Blueprint $table) {
16
+			$table->string('email')->index();
17
+			$table->string('token')->index();
18
+			$table->timestamp('created_at');
19
+		});
20
+	}
21 21
 
22
-    /**
23
-     * Reverse the migrations.
24
-     *
25
-     * @return void
26
-     */
27
-    public function down()
28
-    {
29
-        Schema::drop('password_resets');
30
-    }
22
+	/**
23
+	 * Reverse the migrations.
24
+	 *
25
+	 * @return void
26
+	 */
27
+	public function down()
28
+	{
29
+		Schema::drop('password_resets');
30
+	}
31 31
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
      */
13 13
     public function up()
14 14
     {
15
-        Schema::create('password_resets', function (Blueprint $table) {
15
+        Schema::create('password_resets', function(Blueprint $table) {
16 16
             $table->string('email')->index();
17 17
             $table->string('token')->index();
18 18
             $table->timestamp('created_at');
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Database/Migrations/2015_12_20_124153_users.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@
 block discarded – undo
13 13
 	public function up()
14 14
 	{
15 15
 		Schema::create('users', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('name',100)->nullable();
18
-            $table->string('email')->unique();
19
-            $table->string('password', 60);
20
-            $table->boolean('blocked', 0);
21
-            $table->softDeletes();
22
-            $table->rememberToken();
23
-            $table->timestamps();
24
-        });
16
+			$table->increments('id');
17
+			$table->string('name',100)->nullable();
18
+			$table->string('email')->unique();
19
+			$table->string('password', 60);
20
+			$table->boolean('blocked', 0);
21
+			$table->softDeletes();
22
+			$table->rememberToken();
23
+			$table->timestamps();
24
+		});
25 25
 	}
26 26
 
27 27
 	/**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@
 block discarded – undo
12 12
 	 */
13 13
 	public function up()
14 14
 	{
15
-		Schema::create('users', function (Blueprint $table) {
15
+		Schema::create('users', function(Blueprint $table) {
16 16
             $table->increments('id');
17
-            $table->string('name',100)->nullable();
17
+            $table->string('name', 100)->nullable();
18 18
             $table->string('email')->unique();
19 19
             $table->string('password', 60);
20 20
             $table->boolean('blocked', 0);
Please login to merge, or discard this patch.
src/ApiSkeletonServiceProvider.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -6,26 +6,26 @@
 block discarded – undo
6 6
 
7 7
 class ApiSkeletonServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Perform post-registration booting of services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function boot()
15
-    {
16
-        $this->publishes([
17
-            __DIR__.'/Modules'               => app_path('Modules'),
18
-            __DIR__.'/Modules/V1/Acl/emails' => base_path('resources/views/auth/emails'),
19
-            ]);
20
-    }
9
+	/**
10
+	 * Perform post-registration booting of services.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function boot()
15
+	{
16
+		$this->publishes([
17
+			__DIR__.'/Modules'               => app_path('Modules'),
18
+			__DIR__.'/Modules/V1/Acl/emails' => base_path('resources/views/auth/emails'),
19
+			]);
20
+	}
21 21
 
22
-    /**
23
-     * Register any package services.
24
-     *
25
-     * @return void
26
-     */
27
-    public function register()
28
-    {
29
-        //
30
-    }
22
+	/**
23
+	 * Register any package services.
24
+	 *
25
+	 * @return void
26
+	 */
27
+	public function register()
28
+	{
29
+		//
30
+	}
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/AbstractRepositories/AbstractRepository.php 4 patches
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -435,8 +435,7 @@  discard block
 block discarded – undo
435 435
                 $model->delete();
436 436
                 $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
437 437
             });
438
-        }
439
-        else
438
+        } else
440 439
         {
441 440
             \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
442 441
                 call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
@@ -509,13 +508,11 @@  discard block
 block discarded – undo
509 508
             {
510 509
                 $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
511 510
                 $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
512
-            }
513
-            else if ($key == 'or')
511
+            } else if ($key == 'or')
514 512
             {
515 513
                 $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
516 514
                 $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
517
-            }
518
-            else
515
+            } else
519 516
             {
520 517
                 $conditionString  .= $key . '=? {op} ';
521 518
                 $conditionValues[] = $value;
Please login to merge, or discard this patch.
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      *
33 33
      * @param  array   $relations
34 34
      * @param  string  $sortBy
35
-     * @param  boolean $desc
35
+     * @param  integer $desc
36 36
      * @param  array   $columns
37 37
      * @return collection
38 38
      */
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @param  integer $perPage
51 51
      * @param  array   $relations
52 52
      * @param  string  $sortBy
53
-     * @param  boolean $desc
53
+     * @param  integer $desc
54 54
      * @param  array   $columns
55 55
      * @return collection
56 56
      */
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      * @param  integer $perPage
140 140
      * @param  array   $relations
141 141
      * @param  string  $sortBy
142
-     * @param  boolean $desc
142
+     * @param  integer $desc
143 143
      * @param  array   $columns
144 144
      * @return collection
145 145
      */
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * @param  integer $perPage
158 158
      * @param  array   $relations
159 159
      * @param  string  $sortBy
160
-     * @param  boolean $desc
160
+     * @param  integer $desc
161 161
      * @param  array   $columns
162 162
      * @return collection
163 163
      */
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      * 
175 175
      * @param  array   $data
176 176
      * @param  boolean $saveLog
177
-     * @return object
177
+     * @return boolean
178 178
      */
179 179
     public function save(array $data, $saveLog = true)
180 180
     {
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
      * @param  array   $conditions array of conditions
470 470
      * @param  array   $relations
471 471
      * @param  string  $sortBy
472
-     * @param  boolean $desc
472
+     * @param  integer $desc
473 473
      * @param  array   $columns
474 474
      * @return collection
475 475
      */
Please login to merge, or discard this patch.
Indentation   +492 added lines, -492 removed lines patch added patch discarded remove patch
@@ -4,534 +4,534 @@
 block discarded – undo
4 4
 
5 5
 abstract class AbstractRepository implements RepositoryInterface
6 6
 {
7
-    /**
8
-     * The model implementation.
9
-     * 
10
-     * @var model
11
-     */
12
-    public $model;
7
+	/**
8
+	 * The model implementation.
9
+	 * 
10
+	 * @var model
11
+	 */
12
+	public $model;
13 13
     
14
-    /**
15
-     * The config implementation.
16
-     * 
17
-     * @var config
18
-     */
19
-    protected $config;
14
+	/**
15
+	 * The config implementation.
16
+	 * 
17
+	 * @var config
18
+	 */
19
+	protected $config;
20 20
     
21
-    /**
22
-     * Create new AbstractRepository instance.
23
-     */
24
-    public function __construct()
25
-    {   
26
-        $this->config = \CoreConfig::getConfig();
27
-        $this->model  = \App::make($this->getModel());
28
-    }
21
+	/**
22
+	 * Create new AbstractRepository instance.
23
+	 */
24
+	public function __construct()
25
+	{   
26
+		$this->config = \CoreConfig::getConfig();
27
+		$this->model  = \App::make($this->getModel());
28
+	}
29 29
 
30
-    /**
31
-     * Fetch all records with relations from the storage.
32
-     *
33
-     * @param  array   $relations
34
-     * @param  string  $sortBy
35
-     * @param  boolean $desc
36
-     * @param  array   $columns
37
-     * @return collection
38
-     */
39
-    public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
40
-    {
41
-        $sort = $desc ? 'desc' : 'asc';
42
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns);
43
-    }
30
+	/**
31
+	 * Fetch all records with relations from the storage.
32
+	 *
33
+	 * @param  array   $relations
34
+	 * @param  string  $sortBy
35
+	 * @param  boolean $desc
36
+	 * @param  array   $columns
37
+	 * @return collection
38
+	 */
39
+	public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
40
+	{
41
+		$sort = $desc ? 'desc' : 'asc';
42
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns);
43
+	}
44 44
 
45
-    /**
46
-     * Fetch all records with relations from storage in pages 
47
-     * that matche the given query.
48
-     * 
49
-     * @param  string  $query
50
-     * @param  integer $perPage
51
-     * @param  array   $relations
52
-     * @param  string  $sortBy
53
-     * @param  boolean $desc
54
-     * @param  array   $columns
55
-     * @return collection
56
-     */
57
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
58
-    {
59
-        $model            = call_user_func_array("{$this->getModel()}::with", array($relations));
60
-        $conditionColumns = $this->model->searchable;
61
-        $sort             = $desc ? 'desc' : 'asc';
45
+	/**
46
+	 * Fetch all records with relations from storage in pages 
47
+	 * that matche the given query.
48
+	 * 
49
+	 * @param  string  $query
50
+	 * @param  integer $perPage
51
+	 * @param  array   $relations
52
+	 * @param  string  $sortBy
53
+	 * @param  boolean $desc
54
+	 * @param  array   $columns
55
+	 * @return collection
56
+	 */
57
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
58
+	{
59
+		$model            = call_user_func_array("{$this->getModel()}::with", array($relations));
60
+		$conditionColumns = $this->model->searchable;
61
+		$sort             = $desc ? 'desc' : 'asc';
62 62
 
63
-        /**
64
-         * Construct the select conditions for the model.
65
-         */
66
-        $model->where(function ($q) use ($query, $conditionColumns, $relations){
63
+		/**
64
+		 * Construct the select conditions for the model.
65
+		 */
66
+		$model->where(function ($q) use ($query, $conditionColumns, $relations){
67 67
 
68
-            if (count($conditionColumns)) 
69
-            {
70
-                /**
71
-                 * Use the first element in the model columns to construct the first condition.
72
-                 */
73
-                $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%');
74
-            }
68
+			if (count($conditionColumns)) 
69
+			{
70
+				/**
71
+				 * Use the first element in the model columns to construct the first condition.
72
+				 */
73
+				$q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%');
74
+			}
75 75
 
76
-            /**
77
-             * Loop through the rest of the columns to construct or where conditions.
78
-             */
79
-            foreach ($conditionColumns as $column) 
80
-            {
81
-                $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%');
82
-            }
76
+			/**
77
+			 * Loop through the rest of the columns to construct or where conditions.
78
+			 */
79
+			foreach ($conditionColumns as $column) 
80
+			{
81
+				$q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%');
82
+			}
83 83
 
84
-            /**
85
-             * Loop through the model relations.
86
-             */
87
-            foreach ($relations as $relation) 
88
-            {
89
-                /**
90
-                 * Remove the sub relation if exists.
91
-                 */
92
-                $relation = explode('.', $relation)[0];
84
+			/**
85
+			 * Loop through the model relations.
86
+			 */
87
+			foreach ($relations as $relation) 
88
+			{
89
+				/**
90
+				 * Remove the sub relation if exists.
91
+				 */
92
+				$relation = explode('.', $relation)[0];
93 93
 
94
-                /**
95
-                 * Try to fetch the relation repository from the core.
96
-                 */
97
-                if (\Core::$relation()) 
98
-                {
99
-                    /**
100
-                     * Construct the relation condition.
101
-                     */
102
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation){
94
+				/**
95
+				 * Try to fetch the relation repository from the core.
96
+				 */
97
+				if (\Core::$relation()) 
98
+				{
99
+					/**
100
+					 * Construct the relation condition.
101
+					 */
102
+					$q->orWhereHas($relation, function ($subModel) use ($query, $relation){
103 103
 
104
-                        $subModel->where(function ($q) use ($query, $relation){
104
+						$subModel->where(function ($q) use ($query, $relation){
105 105
 
106
-                            /**
107
-                             * Get columns of the relation.
108
-                             */
109
-                            $subConditionColumns = \Core::$relation()->model->searchable;
106
+							/**
107
+							 * Get columns of the relation.
108
+							 */
109
+							$subConditionColumns = \Core::$relation()->model->searchable;
110 110
 
111
-                            if (count($subConditionColumns)) 
112
-                            {
113
-                                /**
114
-                                * Use the first element in the relation model columns to construct the first condition.
115
-                                 */
116
-                                $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%');
117
-                            }
111
+							if (count($subConditionColumns)) 
112
+							{
113
+								/**
114
+								 * Use the first element in the relation model columns to construct the first condition.
115
+								 */
116
+								$q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%');
117
+							}
118 118
 
119
-                            /**
120
-                             * Loop through the rest of the columns to construct or where conditions.
121
-                             */
122
-                            foreach ($subConditionColumns as $subConditionColumn)
123
-                            {
124
-                                $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%');
125
-                            } 
126
-                        });
119
+							/**
120
+							 * Loop through the rest of the columns to construct or where conditions.
121
+							 */
122
+							foreach ($subConditionColumns as $subConditionColumn)
123
+							{
124
+								$q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%');
125
+							} 
126
+						});
127 127
 
128
-                    });
129
-                }
130
-            }
131
-        });
128
+					});
129
+				}
130
+			}
131
+		});
132 132
         
133
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
134
-    }
133
+		return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
134
+	}
135 135
     
136
-    /**
137
-     * Fetch all records with relations from storage in pages.
138
-     * 
139
-     * @param  integer $perPage
140
-     * @param  array   $relations
141
-     * @param  string  $sortBy
142
-     * @param  boolean $desc
143
-     * @param  array   $columns
144
-     * @return collection
145
-     */
146
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
147
-    {
148
-        $sort = $desc ? 'desc' : 'asc';
149
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns);
150
-    }
136
+	/**
137
+	 * Fetch all records with relations from storage in pages.
138
+	 * 
139
+	 * @param  integer $perPage
140
+	 * @param  array   $relations
141
+	 * @param  string  $sortBy
142
+	 * @param  boolean $desc
143
+	 * @param  array   $columns
144
+	 * @return collection
145
+	 */
146
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
147
+	{
148
+		$sort = $desc ? 'desc' : 'asc';
149
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns);
150
+	}
151 151
 
152
-    /**
153
-     * Fetch all records with relations based on
154
-     * the given condition from storage in pages.
155
-     * 
156
-     * @param  array   $conditions array of conditions
157
-     * @param  integer $perPage
158
-     * @param  array   $relations
159
-     * @param  string  $sortBy
160
-     * @param  boolean $desc
161
-     * @param  array   $columns
162
-     * @return collection
163
-     */
164
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
165
-    {
166
-        unset($conditions['page']);
167
-        $conditions = $this->constructConditions($conditions);
168
-        $sort       = $desc ? 'desc' : 'asc';
169
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
170
-    }
152
+	/**
153
+	 * Fetch all records with relations based on
154
+	 * the given condition from storage in pages.
155
+	 * 
156
+	 * @param  array   $conditions array of conditions
157
+	 * @param  integer $perPage
158
+	 * @param  array   $relations
159
+	 * @param  string  $sortBy
160
+	 * @param  boolean $desc
161
+	 * @param  array   $columns
162
+	 * @return collection
163
+	 */
164
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
165
+	{
166
+		unset($conditions['page']);
167
+		$conditions = $this->constructConditions($conditions);
168
+		$sort       = $desc ? 'desc' : 'asc';
169
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
170
+	}
171 171
     
172
-    /**
173
-     * Save the given model to the storage.
174
-     * 
175
-     * @param  array   $data
176
-     * @param  boolean $saveLog
177
-     * @return object
178
-     */
179
-    public function save(array $data, $saveLog = true)
180
-    {
181
-        $model      = false;
182
-        $modelClass = $this->model;
183
-        $relations  = [];
172
+	/**
173
+	 * Save the given model to the storage.
174
+	 * 
175
+	 * @param  array   $data
176
+	 * @param  boolean $saveLog
177
+	 * @return object
178
+	 */
179
+	public function save(array $data, $saveLog = true)
180
+	{
181
+		$model      = false;
182
+		$modelClass = $this->model;
183
+		$relations  = [];
184 184
 
185
-        \DB::transaction(function () use (&$model, &$relations, $data, $saveLog, $modelClass) {
186
-            /**
187
-             * If the id is present in the data then select the model for updating,
188
-             * else create new model.
189
-             * @var array
190
-             */
191
-            $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
192
-            if ( ! $model) 
193
-            {
194
-                \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
195
-            }
185
+		\DB::transaction(function () use (&$model, &$relations, $data, $saveLog, $modelClass) {
186
+			/**
187
+			 * If the id is present in the data then select the model for updating,
188
+			 * else create new model.
189
+			 * @var array
190
+			 */
191
+			$model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
192
+			if ( ! $model) 
193
+			{
194
+				\ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
195
+			}
196 196
 
197
-            /**
198
-             * Construct the model object with the given data,
199
-             * and if there is a relation add it to relations array,
200
-             * then save the model.
201
-             */
202
-            foreach ($data as $key => $value) 
203
-            {
204
-                /**
205
-                 * If the attribute is a relation.
206
-                 */
207
-                $relation = camel_case($key);
208
-                if (method_exists($model, $relation))
209
-                {
197
+			/**
198
+			 * Construct the model object with the given data,
199
+			 * and if there is a relation add it to relations array,
200
+			 * then save the model.
201
+			 */
202
+			foreach ($data as $key => $value) 
203
+			{
204
+				/**
205
+				 * If the attribute is a relation.
206
+				 */
207
+				$relation = camel_case($key);
208
+				if (method_exists($model, $relation))
209
+				{
210 210
 
211
-                    /**
212
-                     * Check if the relation is a collection.
213
-                     */
214
-                    if (class_basename($model->$relation) == 'Collection') 
215
-                    {   
216
-                        /**
217
-                         * If the relation has no value then marke the relation data 
218
-                         * related to the model to be deleted.
219
-                         */
220
-                        if ( ! $value || ! count($value)) 
221
-                        {
222
-                            $relations[$relation] = 'delete';
223
-                        }   
224
-                    }
225
-                    if (is_array($value)) 
226
-                    {
227
-                        /**
228
-                         * Loop through the relation data.
229
-                         */
230
-                        foreach ($value as $attr => $val) 
231
-                        {
232
-                            /**
233
-                             * Get the relation model.
234
-                             */
235
-                            $relationBaseModel = \Core::$relation()->model;
211
+					/**
212
+					 * Check if the relation is a collection.
213
+					 */
214
+					if (class_basename($model->$relation) == 'Collection') 
215
+					{   
216
+						/**
217
+						 * If the relation has no value then marke the relation data 
218
+						 * related to the model to be deleted.
219
+						 */
220
+						if ( ! $value || ! count($value)) 
221
+						{
222
+							$relations[$relation] = 'delete';
223
+						}   
224
+					}
225
+					if (is_array($value)) 
226
+					{
227
+						/**
228
+						 * Loop through the relation data.
229
+						 */
230
+						foreach ($value as $attr => $val) 
231
+						{
232
+							/**
233
+							 * Get the relation model.
234
+							 */
235
+							$relationBaseModel = \Core::$relation()->model;
236 236
 
237
-                            /**
238
-                             * Check if the relation is a collection.
239
-                             */
240
-                            if (class_basename($model->$relation) == 'Collection')
241
-                            {
242
-                                /**
243
-                                 * If the id is present in the data then select the relation model for updating,
244
-                                 * else create new model.
245
-                                 */
246
-                                $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
237
+							/**
238
+							 * Check if the relation is a collection.
239
+							 */
240
+							if (class_basename($model->$relation) == 'Collection')
241
+							{
242
+								/**
243
+								 * If the id is present in the data then select the relation model for updating,
244
+								 * else create new model.
245
+								 */
246
+								$relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
247 247
 
248
-                                /**
249
-                                 * If model doesn't exists.
250
-                                 */
251
-                                if ( ! $relationModel) 
252
-                                {
253
-                                    \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
254
-                                }
248
+								/**
249
+								 * If model doesn't exists.
250
+								 */
251
+								if ( ! $relationModel) 
252
+								{
253
+									\ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
254
+								}
255 255
 
256
-                                /**
257
-                                 * Loop through the relation attributes.
258
-                                 */
259
-                                foreach ($val as $attr => $val) 
260
-                                {
261
-                                    /**
262
-                                     * Prevent the sub relations or attributes not in the fillable.
263
-                                     */
264
-                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
265
-                                    {
266
-                                        $relationModel->$attr = $val;
267
-                                    }
268
-                                }
269
-                                $relations[$relation][] = $relationModel;
270
-                            }
271
-                            /**
272
-                             * If not collection.
273
-                             */
274
-                            else
275
-                            {
276
-                                /**
277
-                                 * Prevent the sub relations.
278
-                                 */
279
-                                if (gettype($val) !== 'object' && gettype($val) !== 'array') 
280
-                                {
281
-                                    /**
282
-                                     * If the id is present in the data then select the relation model for updating,
283
-                                     * else create new model.
284
-                                     */
285
-                                    $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
256
+								/**
257
+								 * Loop through the relation attributes.
258
+								 */
259
+								foreach ($val as $attr => $val) 
260
+								{
261
+									/**
262
+									 * Prevent the sub relations or attributes not in the fillable.
263
+									 */
264
+									if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
265
+									{
266
+										$relationModel->$attr = $val;
267
+									}
268
+								}
269
+								$relations[$relation][] = $relationModel;
270
+							}
271
+							/**
272
+							 * If not collection.
273
+							 */
274
+							else
275
+							{
276
+								/**
277
+								 * Prevent the sub relations.
278
+								 */
279
+								if (gettype($val) !== 'object' && gettype($val) !== 'array') 
280
+								{
281
+									/**
282
+									 * If the id is present in the data then select the relation model for updating,
283
+									 * else create new model.
284
+									 */
285
+									$relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
286 286
 
287
-                                    /**
288
-                                     * If model doesn't exists.
289
-                                     */
290
-                                    if ( ! $relationModel) 
291
-                                    {
292
-                                        \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
293
-                                    }
287
+									/**
288
+									 * If model doesn't exists.
289
+									 */
290
+									if ( ! $relationModel) 
291
+									{
292
+										\ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
293
+									}
294 294
 
295
-                                    /**
296
-                                     * Prevent attributes not in the fillable.
297
-                                     */
298
-                                    if (array_search($attr, $relationModel->getFillable(), true) !== false) 
299
-                                    {
300
-                                        $relationModel->$attr = $val;
301
-                                        $relations[$relation] = $relationModel;
302
-                                    }
303
-                                }
304
-                            }
305
-                        }
306
-                    }
307
-                }
308
-                /**
309
-                 * If the attribute isn't a relation and prevent attributes not in the fillable.
310
-                 */
311
-                else if (array_search($key, $model->getFillable(), true) !== false)
312
-                {
313
-                    $model->$key = $value;   
314
-                }
315
-            }
316
-            /**
317
-             * Save the model.
318
-             */
319
-            $model->save();
295
+									/**
296
+									 * Prevent attributes not in the fillable.
297
+									 */
298
+									if (array_search($attr, $relationModel->getFillable(), true) !== false) 
299
+									{
300
+										$relationModel->$attr = $val;
301
+										$relations[$relation] = $relationModel;
302
+									}
303
+								}
304
+							}
305
+						}
306
+					}
307
+				}
308
+				/**
309
+				 * If the attribute isn't a relation and prevent attributes not in the fillable.
310
+				 */
311
+				else if (array_search($key, $model->getFillable(), true) !== false)
312
+				{
313
+					$model->$key = $value;   
314
+				}
315
+			}
316
+			/**
317
+			 * Save the model.
318
+			 */
319
+			$model->save();
320 320
 
321
-            /**
322
-             * Loop through the relations array.
323
-             */
324
-            foreach ($relations as $key => $value) 
325
-            {
326
-                /**
327
-                 * If the relation is marked for delete then delete it.
328
-                 */
329
-                if ($value == 'delete' && $model->$key()->count())
330
-                {
331
-                    $model->$key()->delete();
332
-                }
333
-                /**
334
-                 * If the relation is an array.
335
-                 */
336
-                else if (gettype($value) == 'array') 
337
-                {
338
-                    $ids = [];
339
-                    /**
340
-                     * Loop through the relations.
341
-                     */
342
-                    foreach ($value as $val) 
343
-                    {
344
-                        switch (class_basename($model->$key())) 
345
-                        {
346
-                            /**
347
-                             * If the relation is one to many then update it's foreign key with
348
-                             * the model id and save it then add its id to ids array to delete all 
349
-                             * relations who's id isn't in the ids array.
350
-                             */
351
-                            case 'HasMany':
352
-                                $foreignKeyName       = explode('.', $model->$key()->getForeignKey())[1];
353
-                                $val->$foreignKeyName = $model->id;
354
-                                $val->save();
355
-                                $ids[] = $val->id;
356
-                                break;
321
+			/**
322
+			 * Loop through the relations array.
323
+			 */
324
+			foreach ($relations as $key => $value) 
325
+			{
326
+				/**
327
+				 * If the relation is marked for delete then delete it.
328
+				 */
329
+				if ($value == 'delete' && $model->$key()->count())
330
+				{
331
+					$model->$key()->delete();
332
+				}
333
+				/**
334
+				 * If the relation is an array.
335
+				 */
336
+				else if (gettype($value) == 'array') 
337
+				{
338
+					$ids = [];
339
+					/**
340
+					 * Loop through the relations.
341
+					 */
342
+					foreach ($value as $val) 
343
+					{
344
+						switch (class_basename($model->$key())) 
345
+						{
346
+							/**
347
+							 * If the relation is one to many then update it's foreign key with
348
+							 * the model id and save it then add its id to ids array to delete all 
349
+							 * relations who's id isn't in the ids array.
350
+							 */
351
+							case 'HasMany':
352
+								$foreignKeyName       = explode('.', $model->$key()->getForeignKey())[1];
353
+								$val->$foreignKeyName = $model->id;
354
+								$val->save();
355
+								$ids[] = $val->id;
356
+								break;
357 357
 
358
-                            /**
359
-                             * If the relation is many to many then add it's id to the ids array to
360
-                             * attache these ids to the model.
361
-                             */
362
-                            case 'BelongsToMany':
363
-                                $val->save();
364
-                                $ids[] = $val->id;
365
-                                break;
366
-                        }
367
-                    }
368
-                    switch (class_basename($model->$key())) 
369
-                    {
370
-                        /**
371
-                         * If the relation is one to many then delete all 
372
-                         * relations who's id isn't in the ids array.
373
-                         */
374
-                        case 'HasMany':
375
-                            $model->$key()->whereNotIn('id', $ids)->delete();
376
-                            break;
358
+							/**
359
+							 * If the relation is many to many then add it's id to the ids array to
360
+							 * attache these ids to the model.
361
+							 */
362
+							case 'BelongsToMany':
363
+								$val->save();
364
+								$ids[] = $val->id;
365
+								break;
366
+						}
367
+					}
368
+					switch (class_basename($model->$key())) 
369
+					{
370
+						/**
371
+						 * If the relation is one to many then delete all 
372
+						 * relations who's id isn't in the ids array.
373
+						 */
374
+						case 'HasMany':
375
+							$model->$key()->whereNotIn('id', $ids)->delete();
376
+							break;
377 377
 
378
-                        /**
379
-                         * If the relation is many to many then 
380
-                         * detach the previous data and attach 
381
-                         * the ids array to the model.
382
-                         */
383
-                        case 'BelongsToMany':
384
-                            $model->$key()->detach();
385
-                            $model->$key()->attach($ids);
386
-                            break;
387
-                    }
388
-                }
389
-                /**
390
-                 * If the relation isn't array.
391
-                 */
392
-                else
393
-                {
394
-                    switch (class_basename($model->$key())) 
395
-                    {
396
-                        /**
397
-                         * If the relation is one to many or one to one.
398
-                         */
399
-                        case 'BelongsTo':
400
-                            $value->save();
401
-                            $model->$key()->associate($value);
402
-                            $model->save();
403
-                            break;
404
-                    }
405
-                }
406
-            }
378
+						/**
379
+						 * If the relation is many to many then 
380
+						 * detach the previous data and attach 
381
+						 * the ids array to the model.
382
+						 */
383
+						case 'BelongsToMany':
384
+							$model->$key()->detach();
385
+							$model->$key()->attach($ids);
386
+							break;
387
+					}
388
+				}
389
+				/**
390
+				 * If the relation isn't array.
391
+				 */
392
+				else
393
+				{
394
+					switch (class_basename($model->$key())) 
395
+					{
396
+						/**
397
+						 * If the relation is one to many or one to one.
398
+						 */
399
+						case 'BelongsTo':
400
+							$value->save();
401
+							$model->$key()->associate($value);
402
+							$model->save();
403
+							break;
404
+					}
405
+				}
406
+			}
407 407
 
408
-            $saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false;
409
-        });
408
+			$saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false;
409
+		});
410 410
     
411
-        /**
412
-         * return the saved mdel with the given relations.
413
-         */
414
-        return $model;
415
-    }
411
+		/**
412
+		 * return the saved mdel with the given relations.
413
+		 */
414
+		return $model;
415
+	}
416 416
     
417
-    /**
418
-     * Delete record from the storage based on the given
419
-     * condition.
420
-     * 
421
-     * @param  var $value condition value
422
-     * @param  string $attribute condition column name
423
-     * @return void
424
-     */
425
-    public function delete($value, $attribute = 'id', $saveLog = true)
426
-    {
427
-        if ($attribute == 'id') 
428
-        {
429
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
430
-                $model = $this->model->lockForUpdate()->find($value);
431
-                if ( ! $model) 
432
-                {
433
-                    \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value);
434
-                }
417
+	/**
418
+	 * Delete record from the storage based on the given
419
+	 * condition.
420
+	 * 
421
+	 * @param  var $value condition value
422
+	 * @param  string $attribute condition column name
423
+	 * @return void
424
+	 */
425
+	public function delete($value, $attribute = 'id', $saveLog = true)
426
+	{
427
+		if ($attribute == 'id') 
428
+		{
429
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
430
+				$model = $this->model->lockForUpdate()->find($value);
431
+				if ( ! $model) 
432
+				{
433
+					\ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value);
434
+				}
435 435
                 
436
-                $model->delete();
437
-                $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
438
-            });
439
-        }
440
-        else
441
-        {
442
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
443
-                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
444
-                    $model->delete();
445
-                    $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
446
-                });
447
-            });   
448
-        }
449
-    }
436
+				$model->delete();
437
+				$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
438
+			});
439
+		}
440
+		else
441
+		{
442
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
443
+				call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
444
+					$model->delete();
445
+					$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
446
+				});
447
+			});   
448
+		}
449
+	}
450 450
     
451
-    /**
452
-     * Fetch records from the storage based on the given
453
-     * id.
454
-     * 
455
-     * @param  integer $id
456
-     * @param  array   $relations
457
-     * @param  array   $columns
458
-     * @return object
459
-     */
460
-    public function find($id, $relations = [], $columns = array('*'))
461
-    {
462
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
463
-    }
451
+	/**
452
+	 * Fetch records from the storage based on the given
453
+	 * id.
454
+	 * 
455
+	 * @param  integer $id
456
+	 * @param  array   $relations
457
+	 * @param  array   $columns
458
+	 * @return object
459
+	 */
460
+	public function find($id, $relations = [], $columns = array('*'))
461
+	{
462
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
463
+	}
464 464
     
465
-    /**
466
-     * Fetch records from the storage based on the given
467
-     * condition.
468
-     * 
469
-     * @param  array   $conditions array of conditions
470
-     * @param  array   $relations
471
-     * @param  string  $sortBy
472
-     * @param  boolean $desc
473
-     * @param  array   $columns
474
-     * @return collection
475
-     */
476
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
477
-    {
478
-        $conditions = $this->constructConditions($conditions);
479
-        $sort       = $desc ? 'desc' : 'asc';
480
-        return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
481
-    }
465
+	/**
466
+	 * Fetch records from the storage based on the given
467
+	 * condition.
468
+	 * 
469
+	 * @param  array   $conditions array of conditions
470
+	 * @param  array   $relations
471
+	 * @param  string  $sortBy
472
+	 * @param  boolean $desc
473
+	 * @param  array   $columns
474
+	 * @return collection
475
+	 */
476
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
477
+	{
478
+		$conditions = $this->constructConditions($conditions);
479
+		$sort       = $desc ? 'desc' : 'asc';
480
+		return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
481
+	}
482 482
 
483
-    /**
484
-     * Fetch the first record from the storage based on the given
485
-     * condition.
486
-     *
487
-     * @param  array   $conditions array of conditions
488
-     * @param  array   $relations
489
-     * @param  array   $columns
490
-     * @return object
491
-     */
492
-    public function first($conditions, $relations = [], $columns = array('*'))
493
-    {
494
-        $conditions = $this->constructConditions($conditions);
495
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
496
-    }
483
+	/**
484
+	 * Fetch the first record from the storage based on the given
485
+	 * condition.
486
+	 *
487
+	 * @param  array   $conditions array of conditions
488
+	 * @param  array   $relations
489
+	 * @param  array   $columns
490
+	 * @return object
491
+	 */
492
+	public function first($conditions, $relations = [], $columns = array('*'))
493
+	{
494
+		$conditions = $this->constructConditions($conditions);
495
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
496
+	}
497 497
 
498
-    /**
499
-     * Build the conditions recursively for the retrieving methods.
500
-     * @param  array $conditions
501
-     * @return array
502
-     */
503
-    protected function constructConditions($conditions)
504
-    {   
505
-        $conditionString = '';
506
-        $conditionValues = [];
507
-        foreach ($conditions as $key => $value) 
508
-        {
509
-            if ($key == 'and') 
510
-            {
511
-                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
512
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
513
-            }
514
-            else if ($key == 'or')
515
-            {
516
-                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
517
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
518
-            }
519
-            else
520
-            {
521
-                $conditionString  .= $key . '=? {op} ';
522
-                $conditionValues[] = $value;
523
-            }
524
-        }
525
-        $conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
526
-        return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
527
-    }
498
+	/**
499
+	 * Build the conditions recursively for the retrieving methods.
500
+	 * @param  array $conditions
501
+	 * @return array
502
+	 */
503
+	protected function constructConditions($conditions)
504
+	{   
505
+		$conditionString = '';
506
+		$conditionValues = [];
507
+		foreach ($conditions as $key => $value) 
508
+		{
509
+			if ($key == 'and') 
510
+			{
511
+				$conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
512
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
513
+			}
514
+			else if ($key == 'or')
515
+			{
516
+				$conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
517
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
518
+			}
519
+			else
520
+			{
521
+				$conditionString  .= $key . '=? {op} ';
522
+				$conditionValues[] = $value;
523
+			}
524
+		}
525
+		$conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
526
+		return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
527
+	}
528 528
 
529
-    /**
530
-     * Abstract method that return the necessary 
531
-     * information (full model namespace)
532
-     * needed to preform the previous actions.
533
-     * 
534
-     * @return string
535
-     */
536
-    abstract protected function getModel();
529
+	/**
530
+	 * Abstract method that return the necessary 
531
+	 * information (full model namespace)
532
+	 * needed to preform the previous actions.
533
+	 * 
534
+	 * @return string
535
+	 */
536
+	abstract protected function getModel();
537 537
 }
538 538
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
         /**
64 64
          * Construct the select conditions for the model.
65 65
          */
66
-        $model->where(function ($q) use ($query, $conditionColumns, $relations){
66
+        $model->where(function($q) use ($query, $conditionColumns, $relations){
67 67
 
68 68
             if (count($conditionColumns)) 
69 69
             {
70 70
                 /**
71 71
                  * Use the first element in the model columns to construct the first condition.
72 72
                  */
73
-                $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%');
73
+                $q->where(\DB::raw('LOWER('.array_shift($conditionColumns).')'), 'LIKE', '%'.strtolower($query).'%');
74 74
             }
75 75
 
76 76
             /**
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
              */
79 79
             foreach ($conditionColumns as $column) 
80 80
             {
81
-                $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%');
81
+                $q->orWhere(\DB::raw('LOWER('.$column.')'), 'LIKE', '%'.strtolower($query).'%');
82 82
             }
83 83
 
84 84
             /**
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
                     /**
100 100
                      * Construct the relation condition.
101 101
                      */
102
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation){
102
+                    $q->orWhereHas($relation, function($subModel) use ($query, $relation){
103 103
 
104
-                        $subModel->where(function ($q) use ($query, $relation){
104
+                        $subModel->where(function($q) use ($query, $relation){
105 105
 
106 106
                             /**
107 107
                              * Get columns of the relation.
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
                                 /**
114 114
                                 * Use the first element in the relation model columns to construct the first condition.
115 115
                                  */
116
-                                $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%');
116
+                                $q->where(\DB::raw('LOWER('.array_shift($subConditionColumns).')'), 'LIKE', '%'.strtolower($query).'%');
117 117
                             }
118 118
 
119 119
                             /**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                              */
122 122
                             foreach ($subConditionColumns as $subConditionColumn)
123 123
                             {
124
-                                $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%');
124
+                                $q->orWhere(\DB::raw('LOWER('.$subConditionColumn.')'), 'LIKE', '%'.strtolower($query).'%');
125 125
                             } 
126 126
                         });
127 127
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         $modelClass = $this->model;
183 183
         $relations  = [];
184 184
 
185
-        \DB::transaction(function () use (&$model, &$relations, $data, $saveLog, $modelClass) {
185
+        \DB::transaction(function() use (&$model, &$relations, $data, $saveLog, $modelClass) {
186 186
             /**
187 187
              * If the id is present in the data then select the model for updating,
188 188
              * else create new model.
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
192 192
             if ( ! $model) 
193 193
             {
194
-                \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
194
+                \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']);
195 195
             }
196 196
 
197 197
             /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
                                  */
251 251
                                 if ( ! $relationModel) 
252 252
                                 {
253
-                                    \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
253
+                                    \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
254 254
                                 }
255 255
 
256 256
                                 /**
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
                                     /**
262 262
                                      * Prevent the sub relations or attributes not in the fillable.
263 263
                                      */
264
-                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
264
+                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false)
265 265
                                     {
266 266
                                         $relationModel->$attr = $val;
267 267
                                     }
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
                                      */
290 290
                                     if ( ! $relationModel) 
291 291
                                     {
292
-                                        \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
292
+                                        \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
293 293
                                     }
294 294
 
295 295
                                     /**
@@ -426,11 +426,11 @@  discard block
 block discarded – undo
426 426
     {
427 427
         if ($attribute == 'id') 
428 428
         {
429
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
429
+            \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) {
430 430
                 $model = $this->model->lockForUpdate()->find($value);
431 431
                 if ( ! $model) 
432 432
                 {
433
-                    \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value);
433
+                    \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value);
434 434
                 }
435 435
                 
436 436
                 $model->delete();
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
         }
440 440
         else
441 441
         {
442
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
443
-                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
442
+            \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) {
443
+                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) {
444 444
                     $model->delete();
445 445
                     $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
446 446
                 });
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
     {
478 478
         $conditions = $this->constructConditions($conditions);
479 479
         $sort       = $desc ? 'desc' : 'asc';
480
-        return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
480
+        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
481 481
     }
482 482
 
483 483
     /**
@@ -508,21 +508,21 @@  discard block
 block discarded – undo
508 508
         {
509 509
             if ($key == 'and') 
510 510
             {
511
-                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
511
+                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']).' {op} ';
512 512
                 $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
513 513
             }
514 514
             else if ($key == 'or')
515 515
             {
516
-                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
516
+                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']).' {op} ';
517 517
                 $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
518 518
             }
519 519
             else
520 520
             {
521
-                $conditionString  .= $key . '=? {op} ';
521
+                $conditionString  .= $key.'=? {op} ';
522 522
                 $conditionValues[] = $value;
523 523
             }
524 524
         }
525
-        $conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
525
+        $conditionString = '('.rtrim($conditionString, '{op} ').')';
526 526
         return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
527 527
     }
528 528
 
Please login to merge, or discard this patch.
src/Modules/V1/Core/ModelObservers/SettingsObserver.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -5,59 +5,59 @@
 block discarded – undo
5 5
  */
6 6
 class SettingsObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
12
-
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
17
-
18
-    /**
19
-     * Prevent the creating of the settings.
20
-     * 
21
-     * @param  object $model the model beign created.
22
-     * @return void
23
-     */
24
-    public function creating($model)
25
-    {
26
-        \ErrorHandler::cannotCreateSetting();
27
-    }
28
-
29
-    public function created($model)
30
-    {
31
-        //
32
-    }
33
-
34
-    /**
35
-     * Prevent updating of the setting key.
36
-     * 
37
-     * @param  object $model the model beign updated.
38
-     * @return void
39
-     */
40
-    public function updating($model)
41
-    {
42
-        if ($model->getOriginal()['key'] !== $model->key) 
43
-        {
44
-            \ErrorHandler::cannotUpdateSettingKey();
45
-        }
46
-    }
47
-
48
-    public function updated($model)
49
-    {
50
-        //
51
-    }
52
-
53
-    public function deleting($model)
54
-    {
55
-        //
56
-    }
57
-
58
-    public function deleted($model)
59
-    {
60
-        //
61
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12
+
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17
+
18
+	/**
19
+	 * Prevent the creating of the settings.
20
+	 * 
21
+	 * @param  object $model the model beign created.
22
+	 * @return void
23
+	 */
24
+	public function creating($model)
25
+	{
26
+		\ErrorHandler::cannotCreateSetting();
27
+	}
28
+
29
+	public function created($model)
30
+	{
31
+		//
32
+	}
33
+
34
+	/**
35
+	 * Prevent updating of the setting key.
36
+	 * 
37
+	 * @param  object $model the model beign updated.
38
+	 * @return void
39
+	 */
40
+	public function updating($model)
41
+	{
42
+		if ($model->getOriginal()['key'] !== $model->key) 
43
+		{
44
+			\ErrorHandler::cannotUpdateSettingKey();
45
+		}
46
+	}
47
+
48
+	public function updated($model)
49
+	{
50
+		//
51
+	}
52
+
53
+	public function deleting($model)
54
+	{
55
+		//
56
+	}
57
+
58
+	public function deleted($model)
59
+	{
60
+		//
61
+	}
62 62
 
63 63
 }
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Notifications/Repositories/NotificationRepository.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,23 +15,23 @@
 block discarded – undo
15 15
 	}
16 16
 
17 17
 	/**
18
-     * Set the notification notified to true.
19
-     * 
20
-     * @param  integer  $id
21
-     * @return object
22
-     */
23
-    public function notified($id)
24
-    {
25
-        return $this->save(['id' => $id, 'notified' => 1]);
26
-    }
18
+	 * Set the notification notified to true.
19
+	 * 
20
+	 * @param  integer  $id
21
+	 * @return object
22
+	 */
23
+	public function notified($id)
24
+	{
25
+		return $this->save(['id' => $id, 'notified' => 1]);
26
+	}
27 27
 
28
-    /**
29
-     * Set the notification notified to all.
30
-     * 
31
-     * @return void
32
-     */
33
-    public function notifyAll()
34
-    {
35
-        \Core::notifications()->update(false, ['notified' => 1], 'notified');
36
-    }
28
+	/**
29
+	 * Set the notification notified to all.
30
+	 * 
31
+	 * @return void
32
+	 */
33
+	public function notifyAll()
34
+	{
35
+		\Core::notifications()->update(false, ['notified' => 1], 'notified');
36
+	}
37 37
 }
Please login to merge, or discard this patch.