Completed
Push — master ( 7f4033...c0246b )
by Sherif
02:56
created
src/Modules/Acl/Repositories/UserRepository.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,6 +61,6 @@
 block discarded – undo
61 61
 			$user->groups()->attach($group_ids);
62 62
 		});
63 63
 
64
-        return \Core::users()->find($user_id);
64
+		return \Core::users()->find($user_id);
65 65
 	}
66 66
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Repositories/GroupRepository.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,6 +29,6 @@
 block discarded – undo
29 29
 			$group->permissions()->attach($permission_ids);
30 30
 		});
31 31
 
32
-        return \Core::groups()->find($group_id);
32
+		return \Core::groups()->find($group_id);
33 33
 	}
34 34
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Http/Controllers/GroupsController.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -8,35 +8,35 @@
 block discarded – undo
8 8
 
9 9
 class GroupsController extends BaseApiController
10 10
 {
11
-    /**
12
-     * The name of the model that is used by the base api controller 
13
-     * to preform actions like (add, edit ... etc).
14
-     * @var string
15
-     */
16
-    protected $model               = 'groups';
11
+	/**
12
+	 * The name of the model that is used by the base api controller 
13
+	 * to preform actions like (add, edit ... etc).
14
+	 * @var string
15
+	 */
16
+	protected $model               = 'groups';
17 17
 
18
-    /**
19
-     * The validations rules used by the base api controller
20
-     * to check before add.
21
-     * @var array
22
-     */
23
-    protected $validationRules  = [
24
-    'name' => 'required|string|max:100|unique:groups,name,{id}'
25
-    ];
18
+	/**
19
+	 * The validations rules used by the base api controller
20
+	 * to check before add.
21
+	 * @var array
22
+	 */
23
+	protected $validationRules  = [
24
+	'name' => 'required|string|max:100|unique:groups,name,{id}'
25
+	];
26 26
 
27
-    /**
28
-     * Handle an assign permissions to group request.
29
-     *
30
-     * @param  \Illuminate\Http\Request  $request
31
-     * @return \Illuminate\Http\Response
32
-     */
33
-    public function postAssignpermissions(Request $request)
34
-    {
35
-        $this->validate($request, [
36
-            'permission_ids' => 'required|exists:permissions,id', 
37
-            'group_id'       => 'required|exists:groups,id'
38
-            ]);
27
+	/**
28
+	 * Handle an assign permissions to group request.
29
+	 *
30
+	 * @param  \Illuminate\Http\Request  $request
31
+	 * @return \Illuminate\Http\Response
32
+	 */
33
+	public function postAssignpermissions(Request $request)
34
+	{
35
+		$this->validate($request, [
36
+			'permission_ids' => 'required|exists:permissions,id', 
37
+			'group_id'       => 'required|exists:groups,id'
38
+			]);
39 39
 
40
-        return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200);
41
-    }
40
+		return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200);
41
+	}
42 42
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Http/Controllers/UsersController.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -84,8 +84,7 @@
 block discarded – undo
84 84
         {
85 85
             $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
86 86
             return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\Auth::id(), $relations), 200);
87
-        }
88
-        else
87
+        } else
89 88
         {
90 89
             $error = $this->errorHandler->loginFailed();
91 90
             abort($error['status'], $error['message']);
Please login to merge, or discard this patch.
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -7,108 +7,108 @@
 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';
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 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'];
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'];
23 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'];
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'];
30 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
-    ];
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 40
 
41
-    /**
42
-     * Return the logged in user account.
43
-     * 
44
-     * @return object
45
-     */
46
-    public function getAccount()
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
-    }
41
+	/**
42
+	 * Return the logged in user account.
43
+	 * 
44
+	 * @return object
45
+	 */
46
+	public function getAccount()
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 51
 
52
-    /**
53
-     * Logout the user.
54
-     * 
55
-     * @return void
56
-     */
57
-    public function getLogout()
58
-    {
59
-        return \Response::json(\JWTAuth::invalidate(\JWTAuth::getToken()), 200);
60
-    }
52
+	/**
53
+	 * Logout the user.
54
+	 * 
55
+	 * @return void
56
+	 */
57
+	public function getLogout()
58
+	{
59
+		return \Response::json(\JWTAuth::invalidate(\JWTAuth::getToken()), 200);
60
+	}
61 61
 
62
-    /**
63
-     * Handle a registration request.
64
-     *
65
-     * @param  \Illuminate\Http\Request  $request
66
-     * @return \Illuminate\Http\Response
67
-     */
68
-    public function postRegister(Request $request)
69
-    {
70
-        $this->validate($request, ['email' => 'required|email|unique:users,email,{id}', 'password' => 'required|min:6']);
62
+	/**
63
+	 * Handle a registration request.
64
+	 *
65
+	 * @param  \Illuminate\Http\Request  $request
66
+	 * @return \Illuminate\Http\Response
67
+	 */
68
+	public function postRegister(Request $request)
69
+	{
70
+		$this->validate($request, ['email' => 'required|email|unique:users,email,{id}', 'password' => 'required|min:6']);
71 71
 
72
-        $credentials = $request->only('email', 'password');
73
-        $token       = \JWTAuth::fromUser(\Core::users()->model->create($credentials));
74
-        return \Response::json($token, 200);
75
-    }
72
+		$credentials = $request->only('email', 'password');
73
+		$token       = \JWTAuth::fromUser(\Core::users()->model->create($credentials));
74
+		return \Response::json($token, 200);
75
+	}
76 76
 
77
-    /**
78
-     * Handle a login request to the application.
79
-     *
80
-     * @param  \Illuminate\Http\Request  $request
81
-     * @return \Illuminate\Http\Response
82
-     */
83
-    public function postLogin(Request $request)
84
-    {
85
-        $credentials = $request->only('email', 'password');
77
+	/**
78
+	 * Handle a login request to the application.
79
+	 *
80
+	 * @param  \Illuminate\Http\Request  $request
81
+	 * @return \Illuminate\Http\Response
82
+	 */
83
+	public function postLogin(Request $request)
84
+	{
85
+		$credentials = $request->only('email', 'password');
86 86
 
87
-        if ($token = \JWTAuth::attempt($credentials))
88
-        {
89
-            $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
90
-            return \Response::json($token, 200);
91
-        }
92
-        else
93
-        {
94
-            $error = \ErrorHandler::loginFailed();
95
-            abort($error['status'], $error['message']);
96
-        }
97
-    }
87
+		if ($token = \JWTAuth::attempt($credentials))
88
+		{
89
+			$relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
90
+			return \Response::json($token, 200);
91
+		}
92
+		else
93
+		{
94
+			$error = \ErrorHandler::loginFailed();
95
+			abort($error['status'], $error['message']);
96
+		}
97
+	}
98 98
 
99
-    /**
100
-     * Handle an assign groups to user request.
101
-     *
102
-     * @param  \Illuminate\Http\Request  $request
103
-     * @return \Illuminate\Http\Response
104
-     */
105
-    public function postAssigngroups(Request $request)
106
-    {
107
-        $this->validate($request, [
108
-            'group_ids' => 'required|exists:groups,id', 
109
-            'user_id'   => 'required|exists:users,id'
110
-            ]);
99
+	/**
100
+	 * Handle an assign groups to user request.
101
+	 *
102
+	 * @param  \Illuminate\Http\Request  $request
103
+	 * @return \Illuminate\Http\Response
104
+	 */
105
+	public function postAssigngroups(Request $request)
106
+	{
107
+		$this->validate($request, [
108
+			'group_ids' => 'required|exists:groups,id', 
109
+			'user_id'   => 'required|exists:users,id'
110
+			]);
111 111
 
112
-        return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
113
-    }
112
+		return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
113
+	}
114 114
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Http/Controllers/PermissionsController.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,10 +7,10 @@
 block discarded – undo
7 7
 
8 8
 class PermissionsController 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 = 'permissions';
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 = 'permissions';
16 16
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Database/Migrations/2015_12_20_124153_users.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@
 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('first_name',100)->nullable();
18
-            $table->string('last_name',100)->nullable();
19
-            $table->string('user_name',100)->nullable();
20
-            $table->text('address')->nullable();
21
-            $table->string('email')->unique();
22
-            $table->string('password', 60);
23
-            $table->softDeletes();
24
-            $table->rememberToken();
25
-            $table->timestamps();
26
-        });
16
+			$table->increments('id');
17
+			$table->string('first_name',100)->nullable();
18
+			$table->string('last_name',100)->nullable();
19
+			$table->string('user_name',100)->nullable();
20
+			$table->text('address')->nullable();
21
+			$table->string('email')->unique();
22
+			$table->string('password', 60);
23
+			$table->softDeletes();
24
+			$table->rememberToken();
25
+			$table->timestamps();
26
+		});
27 27
 	}
28 28
 
29 29
 	/**
Please login to merge, or discard this patch.
src/Modules/Acl/Database/Migrations/2016_01_05_130506_permissions.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@
 block discarded – undo
12 12
 	 */
13 13
 	public function up()
14 14
 	{
15
-        Schema::create('permissions', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('name',100);
18
-            $table->string('model',100);
19
-            $table->softDeletes();
20
-            $table->timestamps();
21
-            $table->unique(array('name', 'model'));
22
-        });
23
-        Schema::create('groups_permissions', function (Blueprint $table) {
24
-            $table->increments('id');
25
-            $table->integer('group_id');
26
-            $table->integer('permission_id');
27
-            $table->softDeletes();
28
-            $table->timestamps();
29
-        });
15
+		Schema::create('permissions', function (Blueprint $table) {
16
+			$table->increments('id');
17
+			$table->string('name',100);
18
+			$table->string('model',100);
19
+			$table->softDeletes();
20
+			$table->timestamps();
21
+			$table->unique(array('name', 'model'));
22
+		});
23
+		Schema::create('groups_permissions', function (Blueprint $table) {
24
+			$table->increments('id');
25
+			$table->integer('group_id');
26
+			$table->integer('permission_id');
27
+			$table->softDeletes();
28
+			$table->timestamps();
29
+		});
30 30
 	}
31 31
 
32 32
 	/**
Please login to merge, or discard this patch.
src/Modules/Acl/Database/Migrations/2015_12_22_145819_groups.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@
 block discarded – undo
13 13
 	public function up()
14 14
 	{
15 15
 		Schema::create('groups', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('name',100)->unique();
18
-            $table->softDeletes();
19
-            $table->timestamps();
20
-        });
16
+			$table->increments('id');
17
+			$table->string('name',100)->unique();
18
+			$table->softDeletes();
19
+			$table->timestamps();
20
+		});
21 21
         
22
-        Schema::create('users_groups', function (Blueprint $table) {
23
-            $table->increments('id');
24
-            $table->integer('user_id');
25
-            $table->integer('group_id');
26
-            $table->softDeletes();
27
-            $table->timestamps();
28
-        });
22
+		Schema::create('users_groups', function (Blueprint $table) {
23
+			$table->increments('id');
24
+			$table->integer('user_id');
25
+			$table->integer('group_id');
26
+			$table->softDeletes();
27
+			$table->timestamps();
28
+		});
29 29
 	}
30 30
 
31 31
 	/**
Please login to merge, or discard this patch.
src/Modules/Core/AbstractRepositories/AbstractRepository.php 2 patches
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -213,8 +213,7 @@  discard block
 block discarded – undo
213 213
                                     }
214 214
                                 }
215 215
                                 $relations[$relation][] = $relationModel;
216
-                            }
217
-                            else
216
+                            } else
218 217
                             {
219 218
                                 if (gettype($val) !== 'object' && gettype($val) !== 'array') 
220 219
                                 {
@@ -234,8 +233,7 @@  discard block
 block discarded – undo
234 233
                             }
235 234
                         }
236 235
                     }
237
-                }
238
-                else if (array_search($key, $model->getFillable(), true) !== false)
236
+                } else if (array_search($key, $model->getFillable(), true) !== false)
239 237
                 {
240 238
                     $model->$key = $value;   
241 239
                 }
@@ -247,8 +245,7 @@  discard block
 block discarded – undo
247 245
                 if ($value == 'delete' && $model->$key()->count())
248 246
                 {
249 247
                     $model->$key()->delete();
250
-                }
251
-                else if (gettype($value) == 'array') 
248
+                } else if (gettype($value) == 'array') 
252 249
                 {
253 250
                     $ids = [];
254 251
                     foreach ($value as $val) 
@@ -279,8 +276,7 @@  discard block
 block discarded – undo
279 276
                             $model->$key()->attach($ids);
280 277
                             break;
281 278
                     }
282
-                }
283
-                else
279
+                } else
284 280
                 {
285 281
                     switch (class_basename($model->$key())) 
286 282
                     {
@@ -358,8 +354,7 @@  discard block
 block discarded – undo
358 354
                 $model->delete();
359 355
                 $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
360 356
             });
361
-    	}
362
-        else
357
+    	} else
363 358
         {
364 359
             \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
365 360
                 call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
@@ -432,13 +427,11 @@  discard block
 block discarded – undo
432 427
             {
433 428
                 $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
434 429
                 $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
435
-            }
436
-            else if ($key == 'or')
430
+            } else if ($key == 'or')
437 431
             {
438 432
                 $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
439 433
                 $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
440
-            }
441
-            else
434
+            } else
442 435
             {
443 436
                 $conditionString  .= $key . '=? {op} ';
444 437
                 $conditionValues[] = $value;
Please login to merge, or discard this patch.
Indentation   +413 added lines, -413 removed lines patch added patch discarded remove patch
@@ -4,450 +4,450 @@
 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
-     */
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 39
 	public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
40 40
 	{
41
-        $sort = $desc ? 'desc' : 'asc';
42
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns);
41
+		$sort = $desc ? 'desc' : 'asc';
42
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns);
43 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->getFillable();
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->getFillable();
61
+		$sort             = $desc ? 'desc' : 'asc';
62 62
 
63
-        $model->where(function ($q) use ($query, $conditionColumns, $relations){
64
-            $q->where(\DB::raw('LOWER(CAST(' . array_shift($conditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
65
-            foreach ($conditionColumns as $column) 
66
-            {
67
-                $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
68
-            }
69
-            foreach ($relations as $relation) 
70
-            {
71
-                $relation = explode('.', $relation)[0];
72
-                if (\Core::$relation()) 
73
-                {
74
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation){
63
+		$model->where(function ($q) use ($query, $conditionColumns, $relations){
64
+			$q->where(\DB::raw('LOWER(CAST(' . array_shift($conditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
65
+			foreach ($conditionColumns as $column) 
66
+			{
67
+				$q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
68
+			}
69
+			foreach ($relations as $relation) 
70
+			{
71
+				$relation = explode('.', $relation)[0];
72
+				if (\Core::$relation()) 
73
+				{
74
+					$q->orWhereHas($relation, function ($subModel) use ($query, $relation){
75 75
 
76
-                        $subModel->where(function ($q) use ($query, $relation){
76
+						$subModel->where(function ($q) use ($query, $relation){
77 77
 
78
-                            $subConditionColumns = \Core::$relation()->model->getFillable();
79
-                            $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
80
-                            foreach ($subConditionColumns as $subConditionColumn)
81
-                            {
82
-                                $q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
83
-                            } 
84
-                        });
78
+							$subConditionColumns = \Core::$relation()->model->getFillable();
79
+							$q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
80
+							foreach ($subConditionColumns as $subConditionColumn)
81
+							{
82
+								$q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
83
+							} 
84
+						});
85 85
 
86
-                    });
87
-                }
88
-            }
89
-        });
86
+					});
87
+				}
88
+			}
89
+		});
90 90
         
91
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
92
-    }
91
+		return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
92
+	}
93 93
     
94
-    /**
95
-     * Fetch all records with relations from storage in pages.
96
-     * 
97
-     * @param  integer $perPage
98
-     * @param  array   $relations
99
-     * @param  string  $sortBy
100
-     * @param  boolean $desc
101
-     * @param  array   $columns
102
-     * @return collection
103
-     */
104
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
105
-    {
106
-        $sort = $desc ? 'desc' : 'asc';
107
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns);
108
-    }
94
+	/**
95
+	 * Fetch all records with relations from storage in pages.
96
+	 * 
97
+	 * @param  integer $perPage
98
+	 * @param  array   $relations
99
+	 * @param  string  $sortBy
100
+	 * @param  boolean $desc
101
+	 * @param  array   $columns
102
+	 * @return collection
103
+	 */
104
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
105
+	{
106
+		$sort = $desc ? 'desc' : 'asc';
107
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns);
108
+	}
109 109
 
110
-    /**
111
-     * Fetch all records with relations based on
112
-     * the given condition from storage in pages.
113
-     * 
114
-     * @param  array   $conditions array of conditions
115
-     * @param  integer $perPage
116
-     * @param  array   $relations
117
-     * @param  string  $sortBy
118
-     * @param  boolean $desc
119
-     * @param  array   $columns
120
-     * @return collection
121
-     */
122
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
123
-    {
124
-        unset($conditions['page']);
125
-        $conditions = $this->constructConditions($conditions);
126
-        $sort       = $desc ? 'desc' : 'asc';
127
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
128
-    }
110
+	/**
111
+	 * Fetch all records with relations based on
112
+	 * the given condition from storage in pages.
113
+	 * 
114
+	 * @param  array   $conditions array of conditions
115
+	 * @param  integer $perPage
116
+	 * @param  array   $relations
117
+	 * @param  string  $sortBy
118
+	 * @param  boolean $desc
119
+	 * @param  array   $columns
120
+	 * @return collection
121
+	 */
122
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
123
+	{
124
+		unset($conditions['page']);
125
+		$conditions = $this->constructConditions($conditions);
126
+		$sort       = $desc ? 'desc' : 'asc';
127
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
128
+	}
129 129
     
130
-    /**
131
-     * Save the given model to the storage.
132
-     * 
133
-     * @param  array   $data
134
-     * @param  boolean $saveLog
135
-     * @return object
136
-     */
137
-    public function save(array $data, $saveLog = true)
138
-    {
139
-        $model      = false;
140
-        $modelClass = $this->model;
141
-        $relations  = [];
142
-        $with       = [];
130
+	/**
131
+	 * Save the given model to the storage.
132
+	 * 
133
+	 * @param  array   $data
134
+	 * @param  boolean $saveLog
135
+	 * @return object
136
+	 */
137
+	public function save(array $data, $saveLog = true)
138
+	{
139
+		$model      = false;
140
+		$modelClass = $this->model;
141
+		$relations  = [];
142
+		$with       = [];
143 143
 
144
-        \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) {
145
-            /**
146
-             * If the id is present in the data then select the model for updating,
147
-             * else create new model.
148
-             * @var array
149
-             */
150
-            $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
151
-            if ( ! $model) 
152
-            {
153
-                $error = \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
154
-                abort($error['status'], $error['message']);
155
-            }
144
+		\DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) {
145
+			/**
146
+			 * If the id is present in the data then select the model for updating,
147
+			 * else create new model.
148
+			 * @var array
149
+			 */
150
+			$model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
151
+			if ( ! $model) 
152
+			{
153
+				$error = \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
154
+				abort($error['status'], $error['message']);
155
+			}
156 156
 
157
-            /**
158
-             * Construct the model object with the given data,
159
-             * and if there is a relation add it to relations array,
160
-             * then save the model.
161
-             */
162
-            foreach ($data as $key => $value) 
163
-            {
164
-                $relation = camel_case($key);
165
-                if (method_exists($model, $relation))
166
-                {
167
-                    $with[] = $relation;
168
-                    if (class_basename($model->$relation) == 'Collection') 
169
-                    {   
170
-                        if ( ! $value || ! count($value)) 
171
-                        {
172
-                            $relations[$relation] = 'delete';
173
-                        }   
174
-                    }
175
-                    if (is_array($value)) 
176
-                    {
177
-                        foreach ($value as $attr => $val) 
178
-                        {
179
-                            $relationBaseModel = \Core::$relation()->model;
180
-                            if (class_basename($model->$relation) == 'Collection')
181
-                            {
182
-                                $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
183
-                                if ( ! $relationModel) 
184
-                                {
185
-                                    $error = \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
186
-                                    abort($error['status'], $error['message']);
187
-                                }
157
+			/**
158
+			 * Construct the model object with the given data,
159
+			 * and if there is a relation add it to relations array,
160
+			 * then save the model.
161
+			 */
162
+			foreach ($data as $key => $value) 
163
+			{
164
+				$relation = camel_case($key);
165
+				if (method_exists($model, $relation))
166
+				{
167
+					$with[] = $relation;
168
+					if (class_basename($model->$relation) == 'Collection') 
169
+					{   
170
+						if ( ! $value || ! count($value)) 
171
+						{
172
+							$relations[$relation] = 'delete';
173
+						}   
174
+					}
175
+					if (is_array($value)) 
176
+					{
177
+						foreach ($value as $attr => $val) 
178
+						{
179
+							$relationBaseModel = \Core::$relation()->model;
180
+							if (class_basename($model->$relation) == 'Collection')
181
+							{
182
+								$relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
183
+								if ( ! $relationModel) 
184
+								{
185
+									$error = \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
186
+									abort($error['status'], $error['message']);
187
+								}
188 188
 
189
-                                foreach ($val as $attr => $val) 
190
-                                {
191
-                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
192
-                                    {
193
-                                        $relationModel->$attr = $val;
194
-                                    }
195
-                                }
196
-                                $relations[$relation][] = $relationModel;
197
-                            }
198
-                            else
199
-                            {
200
-                                if (gettype($val) !== 'object' && gettype($val) !== 'array') 
201
-                                {
202
-                                    $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
203
-                                    if ( ! $relationModel) 
204
-                                    {
205
-                                        $error = \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
206
-                                        abort($error['status'], $error['message']);
207
-                                    }
189
+								foreach ($val as $attr => $val) 
190
+								{
191
+									if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
192
+									{
193
+										$relationModel->$attr = $val;
194
+									}
195
+								}
196
+								$relations[$relation][] = $relationModel;
197
+							}
198
+							else
199
+							{
200
+								if (gettype($val) !== 'object' && gettype($val) !== 'array') 
201
+								{
202
+									$relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
203
+									if ( ! $relationModel) 
204
+									{
205
+										$error = \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
206
+										abort($error['status'], $error['message']);
207
+									}
208 208
 
209
-                                    if (array_search($attr, $relationModel->getFillable(), true) !== false) 
210
-                                    {
211
-                                        $relationModel->$attr = $val;
212
-                                        $relations[$relation] = $relationModel;
213
-                                    }
214
-                                }
215
-                            }
216
-                        }
217
-                    }
218
-                }
219
-                else if (array_search($key, $model->getFillable(), true) !== false)
220
-                {
221
-                    $model->$key = $value;   
222
-                }
223
-            }
224
-            $model->save();
209
+									if (array_search($attr, $relationModel->getFillable(), true) !== false) 
210
+									{
211
+										$relationModel->$attr = $val;
212
+										$relations[$relation] = $relationModel;
213
+									}
214
+								}
215
+							}
216
+						}
217
+					}
218
+				}
219
+				else if (array_search($key, $model->getFillable(), true) !== false)
220
+				{
221
+					$model->$key = $value;   
222
+				}
223
+			}
224
+			$model->save();
225 225
             
226
-            foreach ($relations as $key => $value) 
227
-            {
228
-                if ($value == 'delete' && $model->$key()->count())
229
-                {
230
-                    $model->$key()->delete();
231
-                }
232
-                else if (gettype($value) == 'array') 
233
-                {
234
-                    $ids = [];
235
-                    foreach ($value as $val) 
236
-                    {
237
-                        switch (class_basename($model->$key())) 
238
-                        {
239
-                            case 'HasMany':
240
-                                $foreignKeyName       = explode('.', $model->$key()->getForeignKey())[1];
241
-                                $val->$foreignKeyName = $model->id;
242
-                                $val->save();
243
-                                $ids[] = $val->id;
244
-                                break;
226
+			foreach ($relations as $key => $value) 
227
+			{
228
+				if ($value == 'delete' && $model->$key()->count())
229
+				{
230
+					$model->$key()->delete();
231
+				}
232
+				else if (gettype($value) == 'array') 
233
+				{
234
+					$ids = [];
235
+					foreach ($value as $val) 
236
+					{
237
+						switch (class_basename($model->$key())) 
238
+						{
239
+							case 'HasMany':
240
+								$foreignKeyName       = explode('.', $model->$key()->getForeignKey())[1];
241
+								$val->$foreignKeyName = $model->id;
242
+								$val->save();
243
+								$ids[] = $val->id;
244
+								break;
245 245
 
246
-                            case 'BelongsToMany':
247
-                                $val->save();
248
-                                $ids[] = $val->id;
249
-                                break;
250
-                        }
251
-                    }
252
-                    switch (class_basename($model->$key())) 
253
-                    {
254
-                        case 'HasMany':
255
-                            $model->$key()->whereNotIn('id', $ids)->delete();
256
-                            break;
246
+							case 'BelongsToMany':
247
+								$val->save();
248
+								$ids[] = $val->id;
249
+								break;
250
+						}
251
+					}
252
+					switch (class_basename($model->$key())) 
253
+					{
254
+						case 'HasMany':
255
+							$model->$key()->whereNotIn('id', $ids)->delete();
256
+							break;
257 257
 
258
-                        case 'BelongsToMany':
259
-                            $model->$key()->detach();
260
-                            $model->$key()->attach($ids);
261
-                            break;
262
-                    }
263
-                }
264
-                else
265
-                {
266
-                    switch (class_basename($model->$key())) 
267
-                    {
268
-                        case 'BelongsTo':
269
-                            $value->save();
270
-                            $model->$key()->associate($value);
271
-                            $model->save();
272
-                            break;
273
-                    }
274
-                }
275
-            }
276
-            $saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false;
277
-        });
258
+						case 'BelongsToMany':
259
+							$model->$key()->detach();
260
+							$model->$key()->attach($ids);
261
+							break;
262
+					}
263
+				}
264
+				else
265
+				{
266
+					switch (class_basename($model->$key())) 
267
+					{
268
+						case 'BelongsTo':
269
+							$value->save();
270
+							$model->$key()->associate($value);
271
+							$model->save();
272
+							break;
273
+					}
274
+				}
275
+			}
276
+			$saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false;
277
+		});
278 278
         
279
-        $this->afterSave($model, $relations);
279
+		$this->afterSave($model, $relations);
280 280
 
281
-        return $this->find($model->id, $with);
282
-    }
281
+		return $this->find($model->id, $with);
282
+	}
283 283
 
284
-    /**
285
-     * Save the given models to the storage.
286
-     * 
287
-     * @param  array   $data
288
-     * @return array
289
-     */
290
-    public function saveMany(array $data)
291
-    {
292
-        $result = [];
293
-        \DB::transaction(function () use (&$result, $data) {
294
-            foreach ($data as $key => $value) 
295
-            {
296
-                $result[] = $this->save($value);
297
-            }
298
-        });
299
-        return $result;
300
-    }
284
+	/**
285
+	 * Save the given models to the storage.
286
+	 * 
287
+	 * @param  array   $data
288
+	 * @return array
289
+	 */
290
+	public function saveMany(array $data)
291
+	{
292
+		$result = [];
293
+		\DB::transaction(function () use (&$result, $data) {
294
+			foreach ($data as $key => $value) 
295
+			{
296
+				$result[] = $this->save($value);
297
+			}
298
+		});
299
+		return $result;
300
+	}
301 301
     
302
-    /**
303
-     * Update record in the storage based on the given
304
-     * condition.
305
-     * 
306
-     * @param  var $value condition value
307
-     * @param  array $data
308
-     * @param  string $attribute condition column name
309
-     * @return void
310
-     */
311
-    public function update($value, array $data, $attribute = 'id', $saveLog = true)
312
-    {
313
-        if ($attribute == 'id') 
314
-        {
315
-            $model = $this->model->lockForUpdate()->find($value);
316
-            $model ? $model->update($data) : 0;
317
-            $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false;
318
-        }
319
-    	call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){
320
-            $model->update($data);
321
-            $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
322
-        });
323
-    }
302
+	/**
303
+	 * Update record in the storage based on the given
304
+	 * condition.
305
+	 * 
306
+	 * @param  var $value condition value
307
+	 * @param  array $data
308
+	 * @param  string $attribute condition column name
309
+	 * @return void
310
+	 */
311
+	public function update($value, array $data, $attribute = 'id', $saveLog = true)
312
+	{
313
+		if ($attribute == 'id') 
314
+		{
315
+			$model = $this->model->lockForUpdate()->find($value);
316
+			$model ? $model->update($data) : 0;
317
+			$saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false;
318
+		}
319
+		call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){
320
+			$model->update($data);
321
+			$saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
322
+		});
323
+	}
324 324
     
325
-    /**
326
-     * Delete record from the storage based on the given
327
-     * condition.
328
-     * 
329
-     * @param  var $value condition value
330
-     * @param  string $attribute condition column name
331
-     * @return void
332
-     */
333
-    public function delete($value, $attribute = 'id', $saveLog = true)
334
-    {
335
-    	if ($attribute == 'id') 
336
-    	{
337
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
338
-                $model = $this->model->lockForUpdate()->find($value);
339
-                $model->delete();
340
-                $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
341
-            });
342
-    	}
343
-        else
344
-        {
345
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
346
-                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
347
-                    $model->delete();
348
-                    $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
349
-                });
350
-            });   
351
-        }
352
-    }
325
+	/**
326
+	 * Delete record from the storage based on the given
327
+	 * condition.
328
+	 * 
329
+	 * @param  var $value condition value
330
+	 * @param  string $attribute condition column name
331
+	 * @return void
332
+	 */
333
+	public function delete($value, $attribute = 'id', $saveLog = true)
334
+	{
335
+		if ($attribute == 'id') 
336
+		{
337
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
338
+				$model = $this->model->lockForUpdate()->find($value);
339
+				$model->delete();
340
+				$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
341
+			});
342
+		}
343
+		else
344
+		{
345
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
346
+				call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
347
+					$model->delete();
348
+					$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
349
+				});
350
+			});   
351
+		}
352
+	}
353 353
     
354
-    /**
355
-     * Fetch records from the storage based on the given
356
-     * id.
357
-     * 
358
-     * @param  integer $id
359
-     * @param  array   $relations
360
-     * @param  array   $columns
361
-     * @return object
362
-     */
363
-    public function find($id, $relations = [], $columns = array('*'))
364
-    {
365
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
366
-    }
354
+	/**
355
+	 * Fetch records from the storage based on the given
356
+	 * id.
357
+	 * 
358
+	 * @param  integer $id
359
+	 * @param  array   $relations
360
+	 * @param  array   $columns
361
+	 * @return object
362
+	 */
363
+	public function find($id, $relations = [], $columns = array('*'))
364
+	{
365
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
366
+	}
367 367
     
368
-    /**
369
-     * Fetch records from the storage based on the given
370
-     * condition.
371
-     * 
372
-     * @param  array   $conditions array of conditions
373
-     * @param  array   $relations
374
-     * @param  string  $sortBy
375
-     * @param  boolean $desc
376
-     * @param  array   $columns
377
-     * @return collection
378
-     */
379
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
380
-    {
381
-        $conditions = $this->constructConditions($conditions);
382
-        $sort       = $desc ? 'desc' : 'asc';
383
-        return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
384
-    }
368
+	/**
369
+	 * Fetch records from the storage based on the given
370
+	 * condition.
371
+	 * 
372
+	 * @param  array   $conditions array of conditions
373
+	 * @param  array   $relations
374
+	 * @param  string  $sortBy
375
+	 * @param  boolean $desc
376
+	 * @param  array   $columns
377
+	 * @return collection
378
+	 */
379
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
380
+	{
381
+		$conditions = $this->constructConditions($conditions);
382
+		$sort       = $desc ? 'desc' : 'asc';
383
+		return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
384
+	}
385 385
 
386
-    /**
387
-     * Fetch the first record from the storage based on the given
388
-     * condition.
389
-     *
390
-     * @param  array   $conditions array of conditions
391
-     * @param  array   $relations
392
-     * @param  array   $columns
393
-     * @return object
394
-     */
395
-    public function first($conditions, $relations = [], $columns = array('*'))
396
-    {
397
-        $conditions = $this->constructConditions($conditions);
398
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
399
-    }
386
+	/**
387
+	 * Fetch the first record from the storage based on the given
388
+	 * condition.
389
+	 *
390
+	 * @param  array   $conditions array of conditions
391
+	 * @param  array   $relations
392
+	 * @param  array   $columns
393
+	 * @return object
394
+	 */
395
+	public function first($conditions, $relations = [], $columns = array('*'))
396
+	{
397
+		$conditions = $this->constructConditions($conditions);
398
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
399
+	}
400 400
 
401
-    /**
402
-     * Build the conditions recursively for the retrieving methods.
403
-     * @param  array $conditions
404
-     * @return array
405
-     */
406
-    protected function constructConditions($conditions)
407
-    {   
408
-        $conditionString = '';
409
-        $conditionValues = [];
410
-        foreach ($conditions as $key => $value) 
411
-        {
412
-            if ($key == 'and') 
413
-            {
414
-                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
415
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
416
-            }
417
-            else if ($key == 'or')
418
-            {
419
-                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
420
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
421
-            }
422
-            else
423
-            {
424
-                $conditionString  .= $key . '=? {op} ';
425
-                $conditionValues[] = $value;
426
-            }
427
-        }
428
-        $conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
429
-        return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
430
-    }
401
+	/**
402
+	 * Build the conditions recursively for the retrieving methods.
403
+	 * @param  array $conditions
404
+	 * @return array
405
+	 */
406
+	protected function constructConditions($conditions)
407
+	{   
408
+		$conditionString = '';
409
+		$conditionValues = [];
410
+		foreach ($conditions as $key => $value) 
411
+		{
412
+			if ($key == 'and') 
413
+			{
414
+				$conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
415
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
416
+			}
417
+			else if ($key == 'or')
418
+			{
419
+				$conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
420
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
421
+			}
422
+			else
423
+			{
424
+				$conditionString  .= $key . '=? {op} ';
425
+				$conditionValues[] = $value;
426
+			}
427
+		}
428
+		$conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
429
+		return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
430
+	}
431 431
 
432
-    /**
433
-     * Abstract method that is called in after
434
-     * the save method finish.
435
-     * 
436
-     * @param  object  $model
437
-     * @param  array   $relations
438
-     * @return void
439
-     */
440
-    protected function afterSave($model, $relations)
441
-    {
442
-        return false;
443
-    }
432
+	/**
433
+	 * Abstract method that is called in after
434
+	 * the save method finish.
435
+	 * 
436
+	 * @param  object  $model
437
+	 * @param  array   $relations
438
+	 * @return void
439
+	 */
440
+	protected function afterSave($model, $relations)
441
+	{
442
+		return false;
443
+	}
444 444
 
445
-    /**
446
-     * Abstract method that return the necessary 
447
-     * information (full model namespace)
448
-     * needed to preform the previous actions.
449
-     * 
450
-     * @return string
451
-     */
452
-    abstract protected function getModel();
445
+	/**
446
+	 * Abstract method that return the necessary 
447
+	 * information (full model namespace)
448
+	 * needed to preform the previous actions.
449
+	 * 
450
+	 * @return string
451
+	 */
452
+	abstract protected function getModel();
453 453
 }
454 454
\ No newline at end of file
Please login to merge, or discard this patch.