Completed
Push — master ( 7f4033...c0246b )
by Sherif
02:56
created
src/Modules/Acl/Database/Migrations/2015_12_22_145819_groups.php 2 patches
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.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
12 12
 	 */
13 13
 	public function up()
14 14
 	{
15
-		Schema::create('groups', function (Blueprint $table) {
15
+		Schema::create('groups', function(Blueprint $table) {
16 16
             $table->increments('id');
17
-            $table->string('name',100)->unique();
17
+            $table->string('name', 100)->unique();
18 18
             $table->softDeletes();
19 19
             $table->timestamps();
20 20
         });
21 21
         
22
-        Schema::create('users_groups', function (Blueprint $table) {
22
+        Schema::create('users_groups', function(Blueprint $table) {
23 23
             $table->increments('id');
24 24
             $table->integer('user_id');
25 25
             $table->integer('group_id');
Please login to merge, or discard this patch.
src/Modules/Acl/AclPermission.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
     
30 30
     public function groups()
31 31
     {
32
-        return $this->belongsToMany('\App\Modules\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps();
32
+        return $this->belongsToMany('\App\Modules\Acl\AclGroup', 'groups_permissions', 'permission_id', 'group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps();
33 33
     }
34 34
 
35 35
     public static function boot()
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -5,36 +5,36 @@
 block discarded – undo
5 5
 
6 6
 class AclPermission extends Model {
7 7
 
8
-    use SoftDeletes;
9
-    protected $table    = 'permissions';
10
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
11
-    protected $hidden   = ['deleted_at'];
12
-    protected $guarded  = ['id'];
13
-    protected $fillable = ['name', 'model'];
8
+	use SoftDeletes;
9
+	protected $table    = 'permissions';
10
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
11
+	protected $hidden   = ['deleted_at'];
12
+	protected $guarded  = ['id'];
13
+	protected $fillable = ['name', 'model'];
14 14
 
15
-    public function getCreatedAtAttribute($value)
16
-    {
17
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
18
-    }
15
+	public function getCreatedAtAttribute($value)
16
+	{
17
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
18
+	}
19 19
 
20
-    public function getUpdatedAtAttribute($value)
21
-    {
22
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
23
-    }
20
+	public function getUpdatedAtAttribute($value)
21
+	{
22
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
23
+	}
24 24
 
25
-    public function getDeletedAtAttribute($value)
26
-    {
27
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
28
-    }
25
+	public function getDeletedAtAttribute($value)
26
+	{
27
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
28
+	}
29 29
     
30
-    public function groups()
31
-    {
32
-        return $this->belongsToMany('\App\Modules\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps();
33
-    }
30
+	public function groups()
31
+	{
32
+		return $this->belongsToMany('\App\Modules\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps();
33
+	}
34 34
 
35
-    public static function boot()
36
-    {
37
-        parent::boot();
38
-        parent::observe(\App::make('App\Modules\Acl\ModelObservers\AclPermissionObserver'));
39
-    }
35
+	public static function boot()
36
+	{
37
+		parent::boot();
38
+		parent::observe(\App::make('App\Modules\Acl\ModelObservers\AclPermissionObserver'));
39
+	}
40 40
 }
Please login to merge, or discard this patch.
src/Modules/Acl/AclUser.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     use SoftDeletes;
10 10
     protected $table    = 'users';
11 11
     protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
-    protected $hidden   = ['password', 'remember_token','deleted_at'];
12
+    protected $hidden   = ['password', 'remember_token', 'deleted_at'];
13 13
     protected $guarded  = ['id'];
14 14
     protected $fillable = ['first_name', 'last_name', 'user_name', 'address', 'email', 'password'];
15 15
     protected $appends  = ['permissions'];
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
     public function groups()
49 49
     {
50
-        return $this->belongsToMany('\App\Modules\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
50
+        return $this->belongsToMany('\App\Modules\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51 51
     }
52 52
 
53 53
     public function getPermissionsAttribute()
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
         $permissions = [];
56 56
         foreach ($this->groups as $group)
57 57
         {
58
-            $group->permissions->each(function ($permission) use (&$permissions){
58
+            $group->permissions->each(function($permission) use (&$permissions){
59 59
                 $permissions[$permission->model][$permission->id] = $permission->name;
60 60
             });
61 61
         }
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@
 block discarded – undo
1 1
 <?php namespace App\Modules\Acl;
2 2
 
3
-use Illuminate\Database\Eloquent\Model;
4 3
 use App\User;
5 4
 use Illuminate\Database\Eloquent\SoftDeletes;
6 5
 
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -6,66 +6,66 @@
 block discarded – undo
6 6
 
7 7
 class AclUser extends User {
8 8
 
9
-    use SoftDeletes;
10
-    protected $table    = 'users';
11
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
-    protected $hidden   = ['password', 'remember_token','deleted_at'];
13
-    protected $guarded  = ['id'];
14
-    protected $fillable = ['first_name', 'last_name', 'user_name', 'address', 'email', 'password'];
15
-    protected $appends  = ['permissions'];
9
+	use SoftDeletes;
10
+	protected $table    = 'users';
11
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
+	protected $hidden   = ['password', 'remember_token','deleted_at'];
13
+	protected $guarded  = ['id'];
14
+	protected $fillable = ['first_name', 'last_name', 'user_name', 'address', 'email', 'password'];
15
+	protected $appends  = ['permissions'];
16 16
     
17
-    public function getCreatedAtAttribute($value)
18
-    {
19
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
20
-    }
17
+	public function getCreatedAtAttribute($value)
18
+	{
19
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
20
+	}
21 21
 
22
-    public function getUpdatedAtAttribute($value)
23
-    {
24
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
25
-    }
22
+	public function getUpdatedAtAttribute($value)
23
+	{
24
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
25
+	}
26 26
 
27
-    public function getDeletedAtAttribute($value)
28
-    {
29
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
30
-    }
27
+	public function getDeletedAtAttribute($value)
28
+	{
29
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
30
+	}
31 31
 
32
-    /**
33
-     * Encrypt the password attribute before
34
-     * saving it in the storage.
35
-     * 
36
-     * @param string $value 
37
-     */
38
-    public function setPasswordAttribute($value)
39
-    {
40
-        $this->attributes['password'] = bcrypt($value);
41
-    }
32
+	/**
33
+	 * Encrypt the password attribute before
34
+	 * saving it in the storage.
35
+	 * 
36
+	 * @param string $value 
37
+	 */
38
+	public function setPasswordAttribute($value)
39
+	{
40
+		$this->attributes['password'] = bcrypt($value);
41
+	}
42 42
 
43
-    public function logs()
44
-    {
45
-        return $this->hasMany('App\Modules\Logging\Log', 'user_id');
46
-    }
43
+	public function logs()
44
+	{
45
+		return $this->hasMany('App\Modules\Logging\Log', 'user_id');
46
+	}
47 47
 
48
-    public function groups()
49
-    {
50
-        return $this->belongsToMany('\App\Modules\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51
-    }
48
+	public function groups()
49
+	{
50
+		return $this->belongsToMany('\App\Modules\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51
+	}
52 52
 
53
-    public function getPermissionsAttribute()
54
-    {
55
-        $permissions = [];
56
-        foreach ($this->groups as $group)
57
-        {
58
-            $group->permissions->each(function ($permission) use (&$permissions){
59
-                $permissions[$permission->model][$permission->id] = $permission->name;
60
-            });
61
-        }
53
+	public function getPermissionsAttribute()
54
+	{
55
+		$permissions = [];
56
+		foreach ($this->groups as $group)
57
+		{
58
+			$group->permissions->each(function ($permission) use (&$permissions){
59
+				$permissions[$permission->model][$permission->id] = $permission->name;
60
+			});
61
+		}
62 62
 
63
-        return \Illuminate\Database\Eloquent\Collection::make($permissions);
64
-    }
63
+		return \Illuminate\Database\Eloquent\Collection::make($permissions);
64
+	}
65 65
 
66
-    public static function boot()
67
-    {
68
-        parent::boot();
69
-        parent::observe(\App::make('App\Modules\Acl\ModelObservers\AclUserObserver'));
70
-    }
66
+	public static function boot()
67
+	{
68
+		parent::boot();
69
+		parent::observe(\App::make('App\Modules\Acl\ModelObservers\AclUserObserver'));
70
+	}
71 71
 }
Please login to merge, or discard this patch.
src/Modules/Core/Settings.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,14 +3,14 @@
 block discarded – undo
3 3
 use Illuminate\Database\Eloquent\Model;
4 4
 use Illuminate\Database\Eloquent\SoftDeletes;
5 5
 
6
-class Settings extends Model{
6
+class Settings extends Model {
7 7
 
8 8
     use SoftDeletes;
9 9
     protected $table    = 'settings';
10 10
     protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
11 11
     protected $hidden   = ['deleted_at'];
12 12
     protected $guarded  = ['id', 'key'];
13
-    protected $fillable = ['name','value'];
13
+    protected $fillable = ['name', 'value'];
14 14
     
15 15
     public function getCreatedAtAttribute($value)
16 16
     {
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -5,31 +5,31 @@
 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'];
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 14
     
15
-    public function getCreatedAtAttribute($value)
16
-    {
17
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
18
-    }
15
+	public function getCreatedAtAttribute($value)
16
+	{
17
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
18
+	}
19 19
 
20
-    public function getUpdatedAtAttribute($value)
21
-    {
22
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
23
-    }
20
+	public function getUpdatedAtAttribute($value)
21
+	{
22
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
23
+	}
24 24
 
25
-    public function getDeletedAtAttribute($value)
26
-    {
27
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
28
-    }
25
+	public function getDeletedAtAttribute($value)
26
+	{
27
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
28
+	}
29 29
 
30
-    public static function boot()
31
-    {
32
-        parent::boot();
33
-        parent::observe(\App::make('App\Modules\Core\ModelObservers\SettingsObserver'));
34
-    }
30
+	public static function boot()
31
+	{
32
+		parent::boot();
33
+		parent::observe(\App::make('App\Modules\Core\ModelObservers\SettingsObserver'));
34
+	}
35 35
 }
Please login to merge, or discard this patch.
src/Modules/Core/AbstractRepositories/AbstractRepository.php 4 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.
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      *
33 33
      * @param  array   $relations
34 34
      * @param  string  $sortBy
35
-     * @param  boolean $desc
35
+     * @param  integer $desc
36 36
      * @param  array   $columns
37 37
      * @return collection
38 38
      */
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @param  integer $perPage
51 51
      * @param  array   $relations
52 52
      * @param  string  $sortBy
53
-     * @param  boolean $desc
53
+     * @param  integer $desc
54 54
      * @param  array   $columns
55 55
      * @return collection
56 56
      */
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      * @param  integer $perPage
98 98
      * @param  array   $relations
99 99
      * @param  string  $sortBy
100
-     * @param  boolean $desc
100
+     * @param  integer $desc
101 101
      * @param  array   $columns
102 102
      * @return collection
103 103
      */
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      * @param  integer $perPage
116 116
      * @param  array   $relations
117 117
      * @param  string  $sortBy
118
-     * @param  boolean $desc
118
+     * @param  integer $desc
119 119
      * @param  array   $columns
120 120
      * @return collection
121 121
      */
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
      * @param  array   $conditions array of conditions
373 373
      * @param  array   $relations
374 374
      * @param  string  $sortBy
375
-     * @param  boolean $desc
375
+     * @param  integer $desc
376 376
      * @param  array   $columns
377 377
      * @return collection
378 378
      */
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
      * Abstract method that is called in after
434 434
      * the save method finish.
435 435
      * 
436
-     * @param  object  $model
436
+     * @param  boolean  $model
437 437
      * @param  array   $relations
438
-     * @return void
438
+     * @return boolean
439 439
      */
440 440
     protected function afterSave($model, $relations)
441 441
     {
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.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -60,26 +60,26 @@  discard block
 block discarded – undo
60 60
         $conditionColumns = $this->model->getFillable();
61 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) . '%');
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 65
             foreach ($conditionColumns as $column) 
66 66
             {
67
-                $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
67
+                $q->orWhere(\DB::raw('LOWER(CAST('.$column.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%');
68 68
             }
69 69
             foreach ($relations as $relation) 
70 70
             {
71 71
                 $relation = explode('.', $relation)[0];
72 72
                 if (\Core::$relation()) 
73 73
                 {
74
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation){
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 78
                             $subConditionColumns = \Core::$relation()->model->getFillable();
79
-                            $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
79
+                            $q->where(\DB::raw('LOWER(CAST('.array_shift($subConditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%');
80 80
                             foreach ($subConditionColumns as $subConditionColumn)
81 81
                             {
82
-                                $q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
82
+                                $q->orWhere(\DB::raw('LOWER(CAST('.$subConditionColumn.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%');
83 83
                             } 
84 84
                         });
85 85
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         $relations  = [];
142 142
         $with       = [];
143 143
 
144
-        \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) {
144
+        \DB::transaction(function() use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) {
145 145
             /**
146 146
              * If the id is present in the data then select the model for updating,
147 147
              * else create new model.
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
             $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
151 151
             if ( ! $model) 
152 152
             {
153
-                $error = \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
153
+                $error = \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']);
154 154
                 abort($error['status'], $error['message']);
155 155
             }
156 156
 
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
                                 $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
183 183
                                 if ( ! $relationModel) 
184 184
                                 {
185
-                                    $error = \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
185
+                                    $error = \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
186 186
                                     abort($error['status'], $error['message']);
187 187
                                 }
188 188
 
189 189
                                 foreach ($val as $attr => $val) 
190 190
                                 {
191
-                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
191
+                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false)
192 192
                                     {
193 193
                                         $relationModel->$attr = $val;
194 194
                                     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                                     $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
203 203
                                     if ( ! $relationModel) 
204 204
                                     {
205
-                                        $error = \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
205
+                                        $error = \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
206 206
                                         abort($error['status'], $error['message']);
207 207
                                     }
208 208
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
     public function saveMany(array $data)
291 291
     {
292 292
         $result = [];
293
-        \DB::transaction(function () use (&$result, $data) {
293
+        \DB::transaction(function() use (&$result, $data) {
294 294
             foreach ($data as $key => $value) 
295 295
             {
296 296
                 $result[] = $this->save($value);
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
             $model ? $model->update($data) : 0;
317 317
             $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false;
318 318
         }
319
-    	call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){
319
+    	call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){
320 320
             $model->update($data);
321 321
             $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
322 322
         });
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
     {
335 335
     	if ($attribute == 'id') 
336 336
     	{
337
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
337
+            \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) {
338 338
                 $model = $this->model->lockForUpdate()->find($value);
339 339
                 $model->delete();
340 340
                 $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
     	}
343 343
         else
344 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){
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 347
                     $model->delete();
348 348
                     $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
349 349
                 });
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
     {
381 381
         $conditions = $this->constructConditions($conditions);
382 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);
383
+        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
384 384
     }
385 385
 
386 386
     /**
@@ -411,21 +411,21 @@  discard block
 block discarded – undo
411 411
         {
412 412
             if ($key == 'and') 
413 413
             {
414
-                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
414
+                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']).' {op} ';
415 415
                 $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
416 416
             }
417 417
             else if ($key == 'or')
418 418
             {
419
-                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
419
+                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']).' {op} ';
420 420
                 $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
421 421
             }
422 422
             else
423 423
             {
424
-                $conditionString  .= $key . '=? {op} ';
424
+                $conditionString  .= $key.'=? {op} ';
425 425
                 $conditionValues[] = $value;
426 426
             }
427 427
         }
428
-        $conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
428
+        $conditionString = '('.rtrim($conditionString, '{op} ').')';
429 429
         return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
430 430
     }
431 431
 
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/RepositoryContainerInterface.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@
 block discarded – undo
4 4
 {
5 5
 	/**
6 6
 	 * Construct the repository class name based on
7
-     * the method name called, search in the 
8
-     * given namespaces for the class and 
9
-     * return an instance.
10
-     * 
11
-     * @param  string $name the called method name
12
-     * @param  array  $arguments the method arguments
13
-     * @return object
14
-     */
7
+	 * the method name called, search in the 
8
+	 * given namespaces for the class and 
9
+	 * return an instance.
10
+	 * 
11
+	 * @param  string $name the called method name
12
+	 * @param  array  $arguments the method arguments
13
+	 * @return object
14
+	 */
15 15
 	public function __call($name, $arguments);
16 16
 }
17 17
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/Core/Http/Controllers/SettingsController.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@
 block discarded – undo
8 8
 
9 9
 class SettingsController 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               = 'settings';
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               = 'settings';
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',
25
-    'value' => 'required|string|max:100'
26
-    ];
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',
25
+	'value' => 'required|string|max:100'
26
+	];
27 27
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,14 +13,14 @@
 block discarded – undo
13 13
      * to preform actions like (add, edit ... etc).
14 14
      * @var string
15 15
      */
16
-    protected $model               = 'settings';
16
+    protected $model = 'settings';
17 17
 
18 18
     /**
19 19
      * The validations rules used by the base api controller
20 20
      * to check before add.
21 21
      * @var array
22 22
      */
23
-    protected $validationRules  = [
23
+    protected $validationRules = [
24 24
     'name'  => 'required|string|max:100',
25 25
     'value' => 'required|string|max:100'
26 26
     ];
Please login to merge, or discard this patch.
src/Modules/Core/Database/Migrations/2016_01_24_123630_settings.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@
 block discarded – undo
13 13
 	public function up()
14 14
 	{
15 15
 		Schema::create('settings', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('name',100);
18
-            $table->string('key',100)->unique();
19
-            $table->string('value',100);
20
-            $table->softDeletes();
21
-            $table->timestamps();
22
-        });
16
+			$table->increments('id');
17
+			$table->string('name',100);
18
+			$table->string('key',100)->unique();
19
+			$table->string('value',100);
20
+			$table->softDeletes();
21
+			$table->timestamps();
22
+		});
23 23
 	}
24 24
 
25 25
 	/**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@
 block discarded – undo
12 12
 	 */
13 13
 	public function up()
14 14
 	{
15
-		Schema::create('settings', function (Blueprint $table) {
15
+		Schema::create('settings', function(Blueprint $table) {
16 16
             $table->increments('id');
17
-            $table->string('name',100);
18
-            $table->string('key',100)->unique();
19
-            $table->string('value',100);
17
+            $table->string('name', 100);
18
+            $table->string('key', 100)->unique();
19
+            $table->string('value', 100);
20 20
             $table->softDeletes();
21 21
             $table->timestamps();
22 22
         });
Please login to merge, or discard this patch.
src/Modules/Notifications/Http/Controllers/NotificationsController.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -8,30 +8,30 @@
 block discarded – undo
8 8
 class NotificationsController extends BaseApiController
9 9
 {
10 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            = 'notifications';
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            = 'notifications';
16 16
 
17
-    /**
18
-     * Set the notification notified to true.
19
-     * 
20
-     * @param  integer  $id
21
-     * @return \Illuminate\Http\Response
22
-     */
23
-    public function getNotified($id)
24
-    {
25
-        return \Response::json(\Core::notifications()->notified($id), 200);
26
-    }
17
+	/**
18
+	 * Set the notification notified to true.
19
+	 * 
20
+	 * @param  integer  $id
21
+	 * @return \Illuminate\Http\Response
22
+	 */
23
+	public function getNotified($id)
24
+	{
25
+		return \Response::json(\Core::notifications()->notified($id), 200);
26
+	}
27 27
 
28
-    /**
29
-     * Set the notification notified to all.
30
-     * 
31
-     * @return \Illuminate\Http\Response
32
-     */
33
-    public function getNotifyall()
34
-    {
35
-        return \Response::json(\Core::notifications()->notifyAll(), 200);
36
-    }
28
+	/**
29
+	 * Set the notification notified to all.
30
+	 * 
31
+	 * @return \Illuminate\Http\Response
32
+	 */
33
+	public function getNotifyall()
34
+	{
35
+		return \Response::json(\Core::notifications()->notifyAll(), 200);
36
+	}
37 37
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
      * to preform actions like (add, edit ... etc).
13 13
      * @var string
14 14
      */
15
-    protected $model            = 'notifications';
15
+    protected $model = 'notifications';
16 16
 
17 17
     /**
18 18
      * Set the notification notified to true.
Please login to merge, or discard this patch.