@@ -51,8 +51,7 @@ |
||
| 51 | 51 | if ($e instanceof \Illuminate\Database\QueryException) |
| 52 | 52 | { |
| 53 | 53 | return \Response::json('Please check the given inputes', '400'); |
| 54 | - } |
|
| 55 | - else if ($e instanceof \predis\connection\connectionexception) |
|
| 54 | + } else if ($e instanceof \predis\connection\connectionexception) |
|
| 56 | 55 | { |
| 57 | 56 | return \Response::json('Your redis notification server isn\'t running', '400'); |
| 58 | 57 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use Illuminate\Database\Eloquent\Model; |
| 4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 5 | 5 | |
| 6 | -class AclGroup extends Model{ |
|
| 6 | +class AclGroup extends Model { |
|
| 7 | 7 | |
| 8 | 8 | use SoftDeletes; |
| 9 | 9 | protected $table = 'groups'; |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function users() |
| 31 | 31 | { |
| 32 | - return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 32 | + return $this->belongsToMany('\App\Modules\Acl\AclUser', 'users_groups', 'group_id', 'user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function permissions() |
| 36 | 36 | { |
| 37 | - return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 37 | + return $this->belongsToMany('\App\Modules\Acl\AclPermission', 'groups_permissions', 'group_id', 'permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public static function boot() |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::create('users', function (Blueprint $table) { |
|
| 15 | + Schema::create('users', function(Blueprint $table) { |
|
| 16 | 16 | $table->increments('id'); |
| 17 | - $table->string('first_name',100)->nullable(); |
|
| 18 | - $table->string('last_name',100)->nullable(); |
|
| 19 | - $table->string('user_name',100)->nullable(); |
|
| 17 | + $table->string('first_name', 100)->nullable(); |
|
| 18 | + $table->string('last_name', 100)->nullable(); |
|
| 19 | + $table->string('user_name', 100)->nullable(); |
|
| 20 | 20 | $table->text('address')->nullable(); |
| 21 | 21 | $table->string('email')->unique(); |
| 22 | 22 | $table->string('password', 60); |
@@ -12,15 +12,15 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::create('permissions', function (Blueprint $table) { |
|
| 15 | + Schema::create('permissions', function(Blueprint $table) { |
|
| 16 | 16 | $table->increments('id'); |
| 17 | - $table->string('name',100); |
|
| 18 | - $table->string('model',100); |
|
| 17 | + $table->string('name', 100); |
|
| 18 | + $table->string('model', 100); |
|
| 19 | 19 | $table->softDeletes(); |
| 20 | 20 | $table->timestamps(); |
| 21 | 21 | $table->unique(array('name', 'model')); |
| 22 | 22 | }); |
| 23 | - Schema::create('groups_permissions', function (Blueprint $table) { |
|
| 23 | + Schema::create('groups_permissions', function(Blueprint $table) { |
|
| 24 | 24 | $table->increments('id'); |
| 25 | 25 | $table->integer('group_id'); |
| 26 | 26 | $table->integer('permission_id'); |
@@ -12,14 +12,14 @@ |
||
| 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'); |
@@ -29,7 +29,7 @@ |
||
| 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() |
@@ -9,7 +9,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -3,14 +3,14 @@ |
||
| 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 | { |
@@ -79,26 +79,26 @@ discard block |
||
| 79 | 79 | $conditionColumns = $this->model->getFillable(); |
| 80 | 80 | $sort = $desc ? 'desc' : 'asc'; |
| 81 | 81 | |
| 82 | - $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
| 83 | - $q->where(\DB::raw('LOWER(CAST(' . array_shift($conditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 82 | + $model->where(function($q) use ($query, $conditionColumns, $relations){ |
|
| 83 | + $q->where(\DB::raw('LOWER(CAST('.array_shift($conditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
| 84 | 84 | foreach ($conditionColumns as $column) |
| 85 | 85 | { |
| 86 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 86 | + $q->orWhere(\DB::raw('LOWER(CAST('.$column.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
| 87 | 87 | } |
| 88 | 88 | foreach ($relations as $relation) |
| 89 | 89 | { |
| 90 | 90 | $relation = explode('.', $relation)[0]; |
| 91 | 91 | if (\Core::$relation()) |
| 92 | 92 | { |
| 93 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
| 93 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation){ |
|
| 94 | 94 | |
| 95 | - $subModel->where(function ($q) use ($query, $relation){ |
|
| 95 | + $subModel->where(function($q) use ($query, $relation){ |
|
| 96 | 96 | |
| 97 | 97 | $subConditionColumns = \Core::$relation()->model->getFillable(); |
| 98 | - $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 98 | + $q->where(\DB::raw('LOWER(CAST('.array_shift($subConditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
| 99 | 99 | foreach ($subConditionColumns as $column) |
| 100 | 100 | { |
| 101 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 101 | + $q->orWhere(\DB::raw('LOWER(CAST('.$column.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
| 102 | 102 | } |
| 103 | 103 | }); |
| 104 | 104 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $relations = []; |
| 161 | 161 | $with = []; |
| 162 | 162 | |
| 163 | - \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
| 163 | + \DB::transaction(function() use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
| 164 | 164 | /** |
| 165 | 165 | * If the id is present in the data then select the model for updating, |
| 166 | 166 | * else create new model. |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
| 170 | 170 | if ( ! $model) |
| 171 | 171 | { |
| 172 | - $error = $this->errorHandler->notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
| 172 | + $error = $this->errorHandler->notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
| 173 | 173 | abort($error['status'], $error['message']); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
| 202 | 202 | if ( ! $relationModel) |
| 203 | 203 | { |
| 204 | - $error = $this->errorHandler->notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
| 204 | + $error = $this->errorHandler->notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
| 205 | 205 | abort($error['status'], $error['message']); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | foreach ($val as $attr => $val) |
| 209 | 209 | { |
| 210 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 210 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 211 | 211 | { |
| 212 | 212 | $relationModel->$attr = $val; |
| 213 | 213 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
| 222 | 222 | if ( ! $relationModel) |
| 223 | 223 | { |
| 224 | - $error = $this->errorHandler->notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
| 224 | + $error = $this->errorHandler->notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
| 225 | 225 | abort($error['status'], $error['message']); |
| 226 | 226 | } |
| 227 | 227 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | public function saveMany(array $data) |
| 310 | 310 | { |
| 311 | 311 | $result = []; |
| 312 | - \DB::transaction(function () use (&$result, $data) { |
|
| 312 | + \DB::transaction(function() use (&$result, $data) { |
|
| 313 | 313 | foreach ($data as $key => $value) |
| 314 | 314 | { |
| 315 | 315 | $result[] = $this->save($value); |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | $model ? $model->update($data) : 0; |
| 336 | 336 | $saveLog ? $this->logs->saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false; |
| 337 | 337 | } |
| 338 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
| 338 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){ |
|
| 339 | 339 | $model->update($data); |
| 340 | 340 | $saveLog ? $this->logs->saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 341 | 341 | }); |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | { |
| 354 | 354 | if ($attribute == 'id') |
| 355 | 355 | { |
| 356 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 356 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 357 | 357 | $model = $this->model->lockForUpdate()->find($value); |
| 358 | 358 | $model->delete(); |
| 359 | 359 | $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
@@ -361,8 +361,8 @@ discard block |
||
| 361 | 361 | } |
| 362 | 362 | else |
| 363 | 363 | { |
| 364 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 365 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
| 364 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 365 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) { |
|
| 366 | 366 | $model->delete(); |
| 367 | 367 | $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 368 | 368 | }); |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | { |
| 400 | 400 | $conditions = $this->constructConditions($conditions); |
| 401 | 401 | $sort = $desc ? 'desc' : 'asc'; |
| 402 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 402 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -430,21 +430,21 @@ discard block |
||
| 430 | 430 | { |
| 431 | 431 | if ($key == 'and') |
| 432 | 432 | { |
| 433 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
| 433 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']).' {op} '; |
|
| 434 | 434 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
| 435 | 435 | } |
| 436 | 436 | else if ($key == 'or') |
| 437 | 437 | { |
| 438 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
| 438 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']).' {op} '; |
|
| 439 | 439 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
| 440 | 440 | } |
| 441 | 441 | else |
| 442 | 442 | { |
| 443 | - $conditionString .= $key . '=? {op} '; |
|
| 443 | + $conditionString .= $key.'=? {op} '; |
|
| 444 | 444 | $conditionValues[] = $value; |
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
| 447 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
| 448 | 448 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
| 449 | 449 | } |
| 450 | 450 | |
@@ -213,8 +213,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |