Completed
Push — master ( 2f8355...903338 )
by Sherif
03:21
created
src/Modules/V1/Acl/ModelObservers/AclUserObserver.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -5,54 +5,54 @@
 block discarded – undo
5 5
  */
6 6
 class AclUserObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
12
-
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
17
-
18
-    public function creating($model)
19
-    {
20
-        //
21
-    }
22
-
23
-    public function created($model)
24
-    {
25
-        //
26
-    }
27
-
28
-    public function updating($model)
29
-    {
30
-        //
31
-    }
32
-
33
-    public function updated($model)
34
-    {
35
-        //
36
-    }
37
-
38
-    /**
39
-     * Soft delete user logs.
40
-     * 
41
-     * @param  object $model the delted model.
42
-     * @return void
43
-     */
44
-    public function deleting($model)
45
-    {
46
-        if ($model->getOriginal()['id'] == \JWTAuth::parseToken()->authenticate()->id) 
47
-        {
48
-            \ErrorHandler::noPermissions();
49
-        }
50
-        $model->logs()->delete();
51
-    }
52
-
53
-    public function deleted($model)
54
-    {
55
-        //
56
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12
+
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17
+
18
+	public function creating($model)
19
+	{
20
+		//
21
+	}
22
+
23
+	public function created($model)
24
+	{
25
+		//
26
+	}
27
+
28
+	public function updating($model)
29
+	{
30
+		//
31
+	}
32
+
33
+	public function updated($model)
34
+	{
35
+		//
36
+	}
37
+
38
+	/**
39
+	 * Soft delete user logs.
40
+	 * 
41
+	 * @param  object $model the delted model.
42
+	 * @return void
43
+	 */
44
+	public function deleting($model)
45
+	{
46
+		if ($model->getOriginal()['id'] == \JWTAuth::parseToken()->authenticate()->id) 
47
+		{
48
+			\ErrorHandler::noPermissions();
49
+		}
50
+		$model->logs()->delete();
51
+	}
52
+
53
+	public function deleted($model)
54
+	{
55
+		//
56
+	}
57 57
 
58 58
 }
59 59
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/Log.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -5,42 +5,42 @@
 block discarded – undo
5 5
 
6 6
 class Log extends Model{
7 7
 
8
-    use SoftDeletes;
9
-    protected $table    = 'logs';
10
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
11
-    protected $hidden   = ['deleted_at', 'item_type'];
12
-    protected $guarded  = ['id'];
13
-    protected $fillable = ['action', 'item_name', 'item_type', 'item_id', 'user_id'];
14
-    public $searchable  = ['action', 'item_name', 'item_type'];
15
-
16
-    public function getCreatedAtAttribute($value)
17
-    {
18
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
19
-    }
20
-
21
-    public function getUpdatedAtAttribute($value)
22
-    {
23
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
24
-    }
25
-
26
-    public function getDeletedAtAttribute($value)
27
-    {
28
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
29
-    }
8
+	use SoftDeletes;
9
+	protected $table    = 'logs';
10
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
11
+	protected $hidden   = ['deleted_at', 'item_type'];
12
+	protected $guarded  = ['id'];
13
+	protected $fillable = ['action', 'item_name', 'item_type', 'item_id', 'user_id'];
14
+	public $searchable  = ['action', 'item_name', 'item_type'];
15
+
16
+	public function getCreatedAtAttribute($value)
17
+	{
18
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
19
+	}
20
+
21
+	public function getUpdatedAtAttribute($value)
22
+	{
23
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
24
+	}
25
+
26
+	public function getDeletedAtAttribute($value)
27
+	{
28
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
29
+	}
30 30
     
31
-    public function user()
32
-    {
33
-        return $this->belongsTo('App\Modules\V1\Acl\AclUser');
34
-    }
35
-
36
-    public function item()
37
-    {
38
-        return $this->morphTo();
39
-    }
40
-
41
-    public static function boot()
42
-    {
43
-        parent::boot();
44
-        parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\LogObserver'));
45
-    }
31
+	public function user()
32
+	{
33
+		return $this->belongsTo('App\Modules\V1\Acl\AclUser');
34
+	}
35
+
36
+	public function item()
37
+	{
38
+		return $this->morphTo();
39
+	}
40
+
41
+	public static function boot()
42
+	{
43
+		parent::boot();
44
+		parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\LogObserver'));
45
+	}
46 46
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/BaseApiController.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -6,215 +6,215 @@
 block discarded – undo
6 6
 
7 7
 class BaseApiController extends Controller
8 8
 {
9
-    /**
10
-     * The model implementation.
11
-     * 
12
-     * @var model
13
-     */
14
-    protected $model;
15
-
16
-    /**
17
-     * The config implementation.
18
-     * 
19
-     * @var config
20
-     */
21
-    protected $config;
22
-
23
-    public function __construct()
24
-    {
25
-        \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
9
+	/**
10
+	 * The model implementation.
11
+	 * 
12
+	 * @var model
13
+	 */
14
+	protected $model;
15
+
16
+	/**
17
+	 * The config implementation.
18
+	 * 
19
+	 * @var config
20
+	 */
21
+	protected $config;
22
+
23
+	public function __construct()
24
+	{
25
+		\Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
26 26
         
27
-        $this->config              = \CoreConfig::getConfig();
28
-        $this->model               = property_exists($this, 'model') ? $this->model : false;
29
-        $this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
30
-        $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
31
-        $this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
32
-        $this->relations           = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
33
-        $route                     = explode('@',\Route::currentRouteAction())[1];
34
-        $this->checkPermission($route);
35
-    }
36
-
37
-    /**
38
-     * Fetch all records with relations from model repository.
39
-     * 
40
-     * @return \Illuminate\Http\Response
41
-     */
42
-    public function index() 
43
-    {
44
-        if ($this->model)
45
-        {
46
-            $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : [];
47
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200);
48
-        }
49
-    }
50
-
51
-    /**
52
-     * Fetch the single object with relations from model repository.
53
-     * 
54
-     * @param  integer $id
55
-     * @return \Illuminate\Http\Response
56
-     */
57
-    public function find($id) 
58
-    {
59
-        if ($this->model) 
60
-        {
61
-            $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
62
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200);
63
-        }
64
-    }
65
-
66
-    /**
67
-     * Paginate all records with relations from model repository
68
-     * that matche the given query.
69
-     * 
70
-     * @param  string  $query
71
-     * @param  integer $perPage
72
-     * @param  string  $sortBy
73
-     * @param  boolean $desc
74
-     * @return \Illuminate\Http\Response
75
-     */
76
-    public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
77
-    {
78
-        if ($this->model) 
79
-        {
80
-            $relations = $this->relations && $this->relations['search'] ? $this->relations['search'] : [];
81
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200);
82
-        }
83
-    }
84
-
85
-    /**
86
-     * Fetch records from the storage based on the given
87
-     * condition.
88
-     * 
89
-     * @param  \Illuminate\Http\Request  $request
90
-     * @param  string  $sortBy
91
-     * @param  boolean $desc
92
-     * @return \Illuminate\Http\Response
93
-     */
94
-    public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
95
-    {
96
-        if ($this->model) 
97
-        {
98
-            $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : [];
99
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200);
100
-        }
101
-    }
102
-
103
-    /**
104
-     * Fetch the first record from the storage based on the given
105
-     * condition.
106
-     * 
107
-     * @param  \Illuminate\Http\Request  $request
108
-     * @return \Illuminate\Http\Response
109
-     */
110
-    public function first(Request $request) 
111
-    {
112
-        if ($this->model) 
113
-        {
114
-            $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : [];
115
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200);
116
-        }
117
-    }
118
-
119
-    /**
120
-     * Paginate all records with relations from model repository.
121
-     * 
122
-     * @param  integer $perPage
123
-     * @param  string  $sortBy
124
-     * @param  boolean $desc
125
-     * @return \Illuminate\Http\Response
126
-     */
127
-    public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
128
-    {
129
-        if ($this->model) 
130
-        {
131
-            $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
132
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200);
133
-        }
134
-    }
135
-
136
-    /**
137
-     * Fetch all records with relations based on
138
-     * the given condition from storage in pages.
139
-     * 
140
-     * @param  \Illuminate\Http\Request  $request
141
-     * @param  integer $perPage
142
-     * @param  string  $sortBy
143
-     * @param  boolean $desc
144
-     * @return \Illuminate\Http\Response
145
-     */
146
-    public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
147
-    {
148
-        if ($this->model) 
149
-        {
150
-            $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : [];
151
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200);
152
-        }
153
-    }
154
-
155
-    /**
156
-     * Save the given model to repository.
157
-     * 
158
-     * @param  \Illuminate\Http\Request  $request
159
-     * @return \Illuminate\Http\Response
160
-     */
161
-    public function save(Request $request) 
162
-    {
163
-        foreach ($this->validationRules as &$rule) 
164
-        {
165
-            if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
166
-            {
167
-                $rule .= ',deleted_at,NULL';
168
-            }
169
-
170
-            if ($request->has('id')) 
171
-            {
172
-                $rule = str_replace('{id}', $request->get('id'), $rule);
173
-            }
174
-            else
175
-            {
176
-                $rule = str_replace(',{id}', '', $rule);
177
-            }
178
-        }
27
+		$this->config              = \CoreConfig::getConfig();
28
+		$this->model               = property_exists($this, 'model') ? $this->model : false;
29
+		$this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
30
+		$this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
31
+		$this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
32
+		$this->relations           = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
33
+		$route                     = explode('@',\Route::currentRouteAction())[1];
34
+		$this->checkPermission($route);
35
+	}
36
+
37
+	/**
38
+	 * Fetch all records with relations from model repository.
39
+	 * 
40
+	 * @return \Illuminate\Http\Response
41
+	 */
42
+	public function index() 
43
+	{
44
+		if ($this->model)
45
+		{
46
+			$relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : [];
47
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200);
48
+		}
49
+	}
50
+
51
+	/**
52
+	 * Fetch the single object with relations from model repository.
53
+	 * 
54
+	 * @param  integer $id
55
+	 * @return \Illuminate\Http\Response
56
+	 */
57
+	public function find($id) 
58
+	{
59
+		if ($this->model) 
60
+		{
61
+			$relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
62
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200);
63
+		}
64
+	}
65
+
66
+	/**
67
+	 * Paginate all records with relations from model repository
68
+	 * that matche the given query.
69
+	 * 
70
+	 * @param  string  $query
71
+	 * @param  integer $perPage
72
+	 * @param  string  $sortBy
73
+	 * @param  boolean $desc
74
+	 * @return \Illuminate\Http\Response
75
+	 */
76
+	public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
77
+	{
78
+		if ($this->model) 
79
+		{
80
+			$relations = $this->relations && $this->relations['search'] ? $this->relations['search'] : [];
81
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200);
82
+		}
83
+	}
84
+
85
+	/**
86
+	 * Fetch records from the storage based on the given
87
+	 * condition.
88
+	 * 
89
+	 * @param  \Illuminate\Http\Request  $request
90
+	 * @param  string  $sortBy
91
+	 * @param  boolean $desc
92
+	 * @return \Illuminate\Http\Response
93
+	 */
94
+	public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
95
+	{
96
+		if ($this->model) 
97
+		{
98
+			$relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : [];
99
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200);
100
+		}
101
+	}
102
+
103
+	/**
104
+	 * Fetch the first record from the storage based on the given
105
+	 * condition.
106
+	 * 
107
+	 * @param  \Illuminate\Http\Request  $request
108
+	 * @return \Illuminate\Http\Response
109
+	 */
110
+	public function first(Request $request) 
111
+	{
112
+		if ($this->model) 
113
+		{
114
+			$relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : [];
115
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200);
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * Paginate all records with relations from model repository.
121
+	 * 
122
+	 * @param  integer $perPage
123
+	 * @param  string  $sortBy
124
+	 * @param  boolean $desc
125
+	 * @return \Illuminate\Http\Response
126
+	 */
127
+	public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
128
+	{
129
+		if ($this->model) 
130
+		{
131
+			$relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
132
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200);
133
+		}
134
+	}
135
+
136
+	/**
137
+	 * Fetch all records with relations based on
138
+	 * the given condition from storage in pages.
139
+	 * 
140
+	 * @param  \Illuminate\Http\Request  $request
141
+	 * @param  integer $perPage
142
+	 * @param  string  $sortBy
143
+	 * @param  boolean $desc
144
+	 * @return \Illuminate\Http\Response
145
+	 */
146
+	public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
147
+	{
148
+		if ($this->model) 
149
+		{
150
+			$relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : [];
151
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200);
152
+		}
153
+	}
154
+
155
+	/**
156
+	 * Save the given model to repository.
157
+	 * 
158
+	 * @param  \Illuminate\Http\Request  $request
159
+	 * @return \Illuminate\Http\Response
160
+	 */
161
+	public function save(Request $request) 
162
+	{
163
+		foreach ($this->validationRules as &$rule) 
164
+		{
165
+			if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
166
+			{
167
+				$rule .= ',deleted_at,NULL';
168
+			}
169
+
170
+			if ($request->has('id')) 
171
+			{
172
+				$rule = str_replace('{id}', $request->get('id'), $rule);
173
+			}
174
+			else
175
+			{
176
+				$rule = str_replace(',{id}', '', $rule);
177
+			}
178
+		}
179 179
         
180
-        $this->validate($request, $this->validationRules);
181
-
182
-        if ($this->model) 
183
-        {
184
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200);
185
-        }
186
-    }
187
-
188
-    /**
189
-     * Delete by the given id from model repository.
190
-     * 
191
-     * @param  integer  $id
192
-     * @return \Illuminate\Http\Response
193
-     */
194
-    public function delete($id) 
195
-    {
196
-        if ($this->model) 
197
-        {
198
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200);
199
-        }
200
-    }
201
-
202
-    /**
203
-     * Check if the logged in user can do the given permission.
204
-     * 
205
-     * @param  string $permission
206
-     * @return void
207
-     */
208
-    private function checkPermission($permission)
209
-    {
210
-        $permission = $permission !== 'index' ? $permission : 'list';
211
-        if ( ! in_array($permission, $this->skipLoginCheck)) 
212
-        {
213
-            \JWTAuth::parseToken()->authenticate();
214
-            if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
215
-            {
216
-                \ErrorHandler::noPermissions();
217
-            }
218
-        }
219
-    }
180
+		$this->validate($request, $this->validationRules);
181
+
182
+		if ($this->model) 
183
+		{
184
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200);
185
+		}
186
+	}
187
+
188
+	/**
189
+	 * Delete by the given id from model repository.
190
+	 * 
191
+	 * @param  integer  $id
192
+	 * @return \Illuminate\Http\Response
193
+	 */
194
+	public function delete($id) 
195
+	{
196
+		if ($this->model) 
197
+		{
198
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200);
199
+		}
200
+	}
201
+
202
+	/**
203
+	 * Check if the logged in user can do the given permission.
204
+	 * 
205
+	 * @param  string $permission
206
+	 * @return void
207
+	 */
208
+	private function checkPermission($permission)
209
+	{
210
+		$permission = $permission !== 'index' ? $permission : 'list';
211
+		if ( ! in_array($permission, $this->skipLoginCheck)) 
212
+		{
213
+			\JWTAuth::parseToken()->authenticate();
214
+			if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
215
+			{
216
+				\ErrorHandler::noPermissions();
217
+			}
218
+		}
219
+	}
220 220
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Settings.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -5,32 +5,32 @@
 block discarded – undo
5 5
 
6 6
 class Settings extends Model{
7 7
 
8
-    use SoftDeletes;
9
-    protected $table    = 'settings';
10
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
11
-    protected $hidden   = ['deleted_at'];
12
-    protected $guarded  = ['id', 'key'];
13
-    protected $fillable = ['name','value'];
14
-    public $searchable  = ['name', 'value', 'key'];
8
+	use SoftDeletes;
9
+	protected $table    = 'settings';
10
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
11
+	protected $hidden   = ['deleted_at'];
12
+	protected $guarded  = ['id', 'key'];
13
+	protected $fillable = ['name','value'];
14
+	public $searchable  = ['name', 'value', 'key'];
15 15
     
16
-    public function getCreatedAtAttribute($value)
17
-    {
18
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
19
-    }
16
+	public function getCreatedAtAttribute($value)
17
+	{
18
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
19
+	}
20 20
 
21
-    public function getUpdatedAtAttribute($value)
22
-    {
23
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
24
-    }
21
+	public function getUpdatedAtAttribute($value)
22
+	{
23
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
24
+	}
25 25
 
26
-    public function getDeletedAtAttribute($value)
27
-    {
28
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
29
-    }
26
+	public function getDeletedAtAttribute($value)
27
+	{
28
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
29
+	}
30 30
 
31
-    public static function boot()
32
-    {
33
-        parent::boot();
34
-        parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\SettingsObserver'));
35
-    }
31
+	public static function boot()
32
+	{
33
+		parent::boot();
34
+		parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\SettingsObserver'));
35
+	}
36 36
 }
Please login to merge, or discard this patch.
src/Modules/V1/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 assignpermissions(Request $request)
34
-    {
35
-        $this->validate($request, [
36
-            'permission_ids' => 'required|exists:permissions,id', 
37
-            'group_id'       => 'required|array|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 assignpermissions(Request $request)
34
+	{
35
+		$this->validate($request, [
36
+			'permission_ids' => 'required|exists:permissions,id', 
37
+			'group_id'       => 'required|array|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/V1/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 $this->find($group_id);
32
+		return $this->find($group_id);
33 33
 	}
34 34
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Interfaces/RepositoryInterface.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -2,119 +2,119 @@
 block discarded – undo
2 2
 
3 3
 interface RepositoryInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     * 
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 * 
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
15 15
     
16
-    /**
17
-     * Fetch all records with relations from storage in pages 
18
-     * that matche the given query.
19
-     * 
20
-     * @param  string  $query
21
-     * @param  integer $perPage
22
-     * @param  array   $relations
23
-     * @param  array   $sortBy
24
-     * @param  array   $desc
25
-     * @param  array   $columns
26
-     * @return collection
27
-     */
28
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
16
+	/**
17
+	 * Fetch all records with relations from storage in pages 
18
+	 * that matche the given query.
19
+	 * 
20
+	 * @param  string  $query
21
+	 * @param  integer $perPage
22
+	 * @param  array   $relations
23
+	 * @param  array   $sortBy
24
+	 * @param  array   $desc
25
+	 * @param  array   $columns
26
+	 * @return collection
27
+	 */
28
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
29 29
 
30
-    /**
31
-     * Fetch all records with relations from storage in pages.
32
-     * 
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
30
+	/**
31
+	 * Fetch all records with relations from storage in pages.
32
+	 * 
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
41 41
     
42
-    /**
43
-     * Fetch all records with relations based on
44
-     * the given condition from storage in pages.
45
-     * 
46
-     * @param  array   $conditions array of conditions
47
-     * @param  integer $perPage
48
-     * @param  array   $relations
49
-     * @param  array   $sortBy
50
-     * @param  array   $desc
51
-     * @param  array   $columns
52
-     * @return collection
53
-     */
54
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
42
+	/**
43
+	 * Fetch all records with relations based on
44
+	 * the given condition from storage in pages.
45
+	 * 
46
+	 * @param  array   $conditions array of conditions
47
+	 * @param  integer $perPage
48
+	 * @param  array   $relations
49
+	 * @param  array   $sortBy
50
+	 * @param  array   $desc
51
+	 * @param  array   $columns
52
+	 * @return collection
53
+	 */
54
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
55 55
 
56
-     /**
57
-     * Save the given model/models to the storage.
58
-     * 
59
-     * @param  array   $data
60
-     * @param  boolean $saveLog
61
-     * @return object
62
-     */
63
-    public function save(array $data, $saveLog = true);
56
+	 /**
57
+	  * Save the given model/models to the storage.
58
+	  * 
59
+	  * @param  array   $data
60
+	  * @param  boolean $saveLog
61
+	  * @return object
62
+	  */
63
+	public function save(array $data, $saveLog = true);
64 64
 
65
-    /**
66
-     * Update record in the storage based on the given
67
-     * condition.
68
-     * 
69
-     * @param  var     $value condition value
70
-     * @param  array   $data
71
-     * @param  string  $attribute condition column name
72
-     * @return integer affected rows
73
-     */
74
-    public function update($value, array $data, $attribute = 'id');
65
+	/**
66
+	 * Update record in the storage based on the given
67
+	 * condition.
68
+	 * 
69
+	 * @param  var     $value condition value
70
+	 * @param  array   $data
71
+	 * @param  string  $attribute condition column name
72
+	 * @return integer affected rows
73
+	 */
74
+	public function update($value, array $data, $attribute = 'id');
75 75
 
76
-    /**
77
-     * Delete record from the storage based on the given
78
-     * condition.
79
-     * 
80
-     * @param  var     $value condition value
81
-     * @param  string  $attribute condition column name
82
-     * @return integer affected rows
83
-     */
84
-    public function delete($value, $attribute = 'id');
76
+	/**
77
+	 * Delete record from the storage based on the given
78
+	 * condition.
79
+	 * 
80
+	 * @param  var     $value condition value
81
+	 * @param  string  $attribute condition column name
82
+	 * @return integer affected rows
83
+	 */
84
+	public function delete($value, $attribute = 'id');
85 85
     
86
-    /**
87
-     * Fetch records from the storage based on the given
88
-     * id.
89
-     * 
90
-     * @param  integer $id
91
-     * @param  array   $relations
92
-     * @param  array   $columns
93
-     * @return object
94
-     */
95
-    public function find($id, $relations = [], $columns = array('*'));
86
+	/**
87
+	 * Fetch records from the storage based on the given
88
+	 * id.
89
+	 * 
90
+	 * @param  integer $id
91
+	 * @param  array   $relations
92
+	 * @param  array   $columns
93
+	 * @return object
94
+	 */
95
+	public function find($id, $relations = [], $columns = array('*'));
96 96
     
97
-    /**
98
-     * Fetch records from the storage based on the given
99
-     * condition.
100
-     * 
101
-     * @param  array   $conditions array of conditions
102
-     * @param  array   $relations
103
-     * @param  array   $sortBy
104
-     * @param  array   $desc
105
-     * @param  array   $columns
106
-     * @return collection
107
-     */
108
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
97
+	/**
98
+	 * Fetch records from the storage based on the given
99
+	 * condition.
100
+	 * 
101
+	 * @param  array   $conditions array of conditions
102
+	 * @param  array   $relations
103
+	 * @param  array   $sortBy
104
+	 * @param  array   $desc
105
+	 * @param  array   $columns
106
+	 * @return collection
107
+	 */
108
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
109 109
 
110
-    /**
111
-     * Fetch the first record fro the storage based on the given
112
-     * condition.
113
-     * 
114
-     * @param  array   $conditions array of conditions
115
-     * @param  array   $relations
116
-     * @param  array   $columns
117
-     * @return object
118
-     */
119
-    public function first($conditions, $relations = [], $columns = array('*'));
110
+	/**
111
+	 * Fetch the first record fro the storage based on the given
112
+	 * condition.
113
+	 * 
114
+	 * @param  array   $conditions array of conditions
115
+	 * @param  array   $relations
116
+	 * @param  array   $columns
117
+	 * @return object
118
+	 */
119
+	public function first($conditions, $relations = [], $columns = array('*'));
120 120
 }
121 121
\ 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
-        $this->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
+		$this->update(false, ['notified' => 1], 'notified');
36
+	}
37 37
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/AbstractRepositories/AbstractRepository.php 1 patch
Indentation   +517 added lines, -517 removed lines patch added patch discarded remove patch
@@ -4,560 +4,560 @@
 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
-     * Update record in the storage based on the given
419
-     * condition.
420
-     * 
421
-     * @param  [type] $value condition value
422
-     * @param  array $data
423
-     * @param  string $attribute condition column name
424
-     * @return void
425
-     */
426
-    public function update($value, array $data, $attribute = 'id', $saveLog = true)
427
-    {
428
-        if ($attribute == 'id') 
429
-        {
430
-            $model = $this->model->lockForUpdate()->find($value);
431
-            $model ? $model->update($data) : 0;
432
-            $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false;
433
-        }
434
-        else
435
-        {
436
-            call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){
437
-                $model->update($data);
438
-                $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
439
-            });
440
-        }
441
-    }
417
+	/**
418
+	 * Update record in the storage based on the given
419
+	 * condition.
420
+	 * 
421
+	 * @param  [type] $value condition value
422
+	 * @param  array $data
423
+	 * @param  string $attribute condition column name
424
+	 * @return void
425
+	 */
426
+	public function update($value, array $data, $attribute = 'id', $saveLog = true)
427
+	{
428
+		if ($attribute == 'id') 
429
+		{
430
+			$model = $this->model->lockForUpdate()->find($value);
431
+			$model ? $model->update($data) : 0;
432
+			$saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false;
433
+		}
434
+		else
435
+		{
436
+			call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){
437
+				$model->update($data);
438
+				$saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
439
+			});
440
+		}
441
+	}
442 442
 
443
-    /**
444
-     * Delete record from the storage based on the given
445
-     * condition.
446
-     * 
447
-     * @param  var $value condition value
448
-     * @param  string $attribute condition column name
449
-     * @return void
450
-     */
451
-    public function delete($value, $attribute = 'id', $saveLog = true)
452
-    {
453
-        if ($attribute == 'id') 
454
-        {
455
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
456
-                $model = $this->model->lockForUpdate()->find($value);
457
-                if ( ! $model) 
458
-                {
459
-                    \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value);
460
-                }
443
+	/**
444
+	 * Delete record from the storage based on the given
445
+	 * condition.
446
+	 * 
447
+	 * @param  var $value condition value
448
+	 * @param  string $attribute condition column name
449
+	 * @return void
450
+	 */
451
+	public function delete($value, $attribute = 'id', $saveLog = true)
452
+	{
453
+		if ($attribute == 'id') 
454
+		{
455
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
456
+				$model = $this->model->lockForUpdate()->find($value);
457
+				if ( ! $model) 
458
+				{
459
+					\ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value);
460
+				}
461 461
                 
462
-                $model->delete();
463
-                $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
464
-            });
465
-        }
466
-        else
467
-        {
468
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
469
-                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
470
-                    $model->delete();
471
-                    $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
472
-                });
473
-            });   
474
-        }
475
-    }
462
+				$model->delete();
463
+				$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
464
+			});
465
+		}
466
+		else
467
+		{
468
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
469
+				call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
470
+					$model->delete();
471
+					$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
472
+				});
473
+			});   
474
+		}
475
+	}
476 476
     
477
-    /**
478
-     * Fetch records from the storage based on the given
479
-     * id.
480
-     * 
481
-     * @param  integer $id
482
-     * @param  array   $relations
483
-     * @param  array   $columns
484
-     * @return object
485
-     */
486
-    public function find($id, $relations = [], $columns = array('*'))
487
-    {
488
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
489
-    }
477
+	/**
478
+	 * Fetch records from the storage based on the given
479
+	 * id.
480
+	 * 
481
+	 * @param  integer $id
482
+	 * @param  array   $relations
483
+	 * @param  array   $columns
484
+	 * @return object
485
+	 */
486
+	public function find($id, $relations = [], $columns = array('*'))
487
+	{
488
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
489
+	}
490 490
     
491
-    /**
492
-     * Fetch records from the storage based on the given
493
-     * condition.
494
-     * 
495
-     * @param  array   $conditions array of conditions
496
-     * @param  array   $relations
497
-     * @param  string  $sortBy
498
-     * @param  boolean $desc
499
-     * @param  array   $columns
500
-     * @return collection
501
-     */
502
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
503
-    {
504
-        $conditions = $this->constructConditions($conditions);
505
-        $sort       = $desc ? 'desc' : 'asc';
506
-        return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
507
-    }
491
+	/**
492
+	 * Fetch records from the storage based on the given
493
+	 * condition.
494
+	 * 
495
+	 * @param  array   $conditions array of conditions
496
+	 * @param  array   $relations
497
+	 * @param  string  $sortBy
498
+	 * @param  boolean $desc
499
+	 * @param  array   $columns
500
+	 * @return collection
501
+	 */
502
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
503
+	{
504
+		$conditions = $this->constructConditions($conditions);
505
+		$sort       = $desc ? 'desc' : 'asc';
506
+		return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
507
+	}
508 508
 
509
-    /**
510
-     * Fetch the first record from the storage based on the given
511
-     * condition.
512
-     *
513
-     * @param  array   $conditions array of conditions
514
-     * @param  array   $relations
515
-     * @param  array   $columns
516
-     * @return object
517
-     */
518
-    public function first($conditions, $relations = [], $columns = array('*'))
519
-    {
520
-        $conditions = $this->constructConditions($conditions);
521
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
522
-    }
509
+	/**
510
+	 * Fetch the first record from the storage based on the given
511
+	 * condition.
512
+	 *
513
+	 * @param  array   $conditions array of conditions
514
+	 * @param  array   $relations
515
+	 * @param  array   $columns
516
+	 * @return object
517
+	 */
518
+	public function first($conditions, $relations = [], $columns = array('*'))
519
+	{
520
+		$conditions = $this->constructConditions($conditions);
521
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
522
+	}
523 523
 
524
-    /**
525
-     * Build the conditions recursively for the retrieving methods.
526
-     * @param  array $conditions
527
-     * @return array
528
-     */
529
-    protected function constructConditions($conditions)
530
-    {   
531
-        $conditionString = '';
532
-        $conditionValues = [];
533
-        foreach ($conditions as $key => $value) 
534
-        {
535
-            if ($key == 'and') 
536
-            {
537
-                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
538
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
539
-            }
540
-            else if ($key == 'or')
541
-            {
542
-                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
543
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
544
-            }
545
-            else
546
-            {
547
-                $conditionString  .= $key . '=? {op} ';
548
-                $conditionValues[] = $value;
549
-            }
550
-        }
551
-        $conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
552
-        return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
553
-    }
524
+	/**
525
+	 * Build the conditions recursively for the retrieving methods.
526
+	 * @param  array $conditions
527
+	 * @return array
528
+	 */
529
+	protected function constructConditions($conditions)
530
+	{   
531
+		$conditionString = '';
532
+		$conditionValues = [];
533
+		foreach ($conditions as $key => $value) 
534
+		{
535
+			if ($key == 'and') 
536
+			{
537
+				$conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
538
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
539
+			}
540
+			else if ($key == 'or')
541
+			{
542
+				$conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
543
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
544
+			}
545
+			else
546
+			{
547
+				$conditionString  .= $key . '=? {op} ';
548
+				$conditionValues[] = $value;
549
+			}
550
+		}
551
+		$conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
552
+		return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
553
+	}
554 554
 
555
-    /**
556
-     * Abstract method that return the necessary 
557
-     * information (full model namespace)
558
-     * needed to preform the previous actions.
559
-     * 
560
-     * @return string
561
-     */
562
-    abstract protected function getModel();
555
+	/**
556
+	 * Abstract method that return the necessary 
557
+	 * information (full model namespace)
558
+	 * needed to preform the previous actions.
559
+	 * 
560
+	 * @return string
561
+	 */
562
+	abstract protected function getModel();
563 563
 }
564 564
\ No newline at end of file
Please login to merge, or discard this patch.