@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @param array $relations |
| 53 | 53 | * @param string $sortBy |
| 54 | - * @param boolean $desc |
|
| 54 | + * @param integer $desc |
|
| 55 | 55 | * @param array $columns |
| 56 | 56 | * @return collection |
| 57 | 57 | */ |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param integer $perPage |
| 70 | 70 | * @param array $relations |
| 71 | 71 | * @param string $sortBy |
| 72 | - * @param boolean $desc |
|
| 72 | + * @param integer $desc |
|
| 73 | 73 | * @param array $columns |
| 74 | 74 | * @return collection |
| 75 | 75 | */ |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @param integer $perPage |
| 117 | 117 | * @param array $relations |
| 118 | 118 | * @param string $sortBy |
| 119 | - * @param boolean $desc |
|
| 119 | + * @param integer $desc |
|
| 120 | 120 | * @param array $columns |
| 121 | 121 | * @return collection |
| 122 | 122 | */ |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param integer $perPage |
| 135 | 135 | * @param array $relations |
| 136 | 136 | * @param string $sortBy |
| 137 | - * @param boolean $desc |
|
| 137 | + * @param integer $desc |
|
| 138 | 138 | * @param array $columns |
| 139 | 139 | * @return collection |
| 140 | 140 | */ |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | * @param array $conditions array of conditions |
| 392 | 392 | * @param array $relations |
| 393 | 393 | * @param string $sortBy |
| 394 | - * @param boolean $desc |
|
| 394 | + * @param integer $desc |
|
| 395 | 395 | * @param array $columns |
| 396 | 396 | * @return collection |
| 397 | 397 | */ |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * |
| 409 | 409 | * @param array $conditions array of conditions |
| 410 | 410 | * @param array $relations |
| 411 | - * @param array $colunmns |
|
| 411 | + * @param array $columns |
|
| 412 | 412 | * @return object |
| 413 | 413 | */ |
| 414 | 414 | public function first($conditions, $relations = [], $columns = array('*')) |
@@ -452,9 +452,9 @@ discard block |
||
| 452 | 452 | * Abstract method that is called in after |
| 453 | 453 | * the save method finish. |
| 454 | 454 | * |
| 455 | - * @param object $model |
|
| 455 | + * @param boolean $model |
|
| 456 | 456 | * @param array $relations |
| 457 | - * @return void |
|
| 457 | + * @return boolean |
|
| 458 | 458 | */ |
| 459 | 459 | protected function afterSave($model, $relations) |
| 460 | 460 | { |
@@ -7,466 +7,466 @@ |
||
| 7 | 7 | |
| 8 | 8 | abstract class AbstractRepository implements RepositoryInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The model implementation. |
|
| 12 | - * |
|
| 13 | - * @var model |
|
| 14 | - */ |
|
| 15 | - public $model; |
|
| 10 | + /** |
|
| 11 | + * The model implementation. |
|
| 12 | + * |
|
| 13 | + * @var model |
|
| 14 | + */ |
|
| 15 | + public $model; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The errorHandler implementation. |
|
| 19 | - * |
|
| 20 | - * @var errorHandler |
|
| 21 | - */ |
|
| 22 | - protected $errorHandler; |
|
| 17 | + /** |
|
| 18 | + * The errorHandler implementation. |
|
| 19 | + * |
|
| 20 | + * @var errorHandler |
|
| 21 | + */ |
|
| 22 | + protected $errorHandler; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The logs implementation. |
|
| 26 | - * |
|
| 27 | - * @var logs |
|
| 28 | - */ |
|
| 29 | - protected $logs; |
|
| 24 | + /** |
|
| 25 | + * The logs implementation. |
|
| 26 | + * |
|
| 27 | + * @var logs |
|
| 28 | + */ |
|
| 29 | + protected $logs; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The config implementation. |
|
| 33 | - * |
|
| 34 | - * @var config |
|
| 35 | - */ |
|
| 36 | - protected $config; |
|
| 31 | + /** |
|
| 32 | + * The config implementation. |
|
| 33 | + * |
|
| 34 | + * @var config |
|
| 35 | + */ |
|
| 36 | + protected $config; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Create new AbstractRepository instance. |
|
| 40 | - */ |
|
| 41 | - public function __construct(ErrorHandler $errorHandler, CoreConfig $config, Log $logs) |
|
| 42 | - { |
|
| 43 | - $this->errorHandler = $errorHandler; |
|
| 44 | - $this->config = $config->getConfig(); |
|
| 45 | - $this->logs = $logs; |
|
| 46 | - $this->model = \App::make($this->getModel()); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * Create new AbstractRepository instance. |
|
| 40 | + */ |
|
| 41 | + public function __construct(ErrorHandler $errorHandler, CoreConfig $config, Log $logs) |
|
| 42 | + { |
|
| 43 | + $this->errorHandler = $errorHandler; |
|
| 44 | + $this->config = $config->getConfig(); |
|
| 45 | + $this->logs = $logs; |
|
| 46 | + $this->model = \App::make($this->getModel()); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Fetch all records with relations from the storage. |
|
| 51 | - * |
|
| 52 | - * @param array $relations |
|
| 53 | - * @param string $sortBy |
|
| 54 | - * @param boolean $desc |
|
| 55 | - * @param array $columns |
|
| 56 | - * @return collection |
|
| 57 | - */ |
|
| 49 | + /** |
|
| 50 | + * Fetch all records with relations from the storage. |
|
| 51 | + * |
|
| 52 | + * @param array $relations |
|
| 53 | + * @param string $sortBy |
|
| 54 | + * @param boolean $desc |
|
| 55 | + * @param array $columns |
|
| 56 | + * @return collection |
|
| 57 | + */ |
|
| 58 | 58 | public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
| 59 | 59 | { |
| 60 | - $sort = $desc ? 'desc' : 'asc'; |
|
| 61 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns); |
|
| 60 | + $sort = $desc ? 'desc' : 'asc'; |
|
| 61 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Fetch all records with relations from storage in pages |
|
| 66 | - * that matche the given query. |
|
| 67 | - * |
|
| 68 | - * @param string $query |
|
| 69 | - * @param integer $perPage |
|
| 70 | - * @param array $relations |
|
| 71 | - * @param string $sortBy |
|
| 72 | - * @param boolean $desc |
|
| 73 | - * @param array $columns |
|
| 74 | - * @return collection |
|
| 75 | - */ |
|
| 76 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
| 77 | - { |
|
| 78 | - $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
| 79 | - $conditionColumns = $this->model->getFillable(); |
|
| 80 | - $sort = $desc ? 'desc' : 'asc'; |
|
| 64 | + /** |
|
| 65 | + * Fetch all records with relations from storage in pages |
|
| 66 | + * that matche the given query. |
|
| 67 | + * |
|
| 68 | + * @param string $query |
|
| 69 | + * @param integer $perPage |
|
| 70 | + * @param array $relations |
|
| 71 | + * @param string $sortBy |
|
| 72 | + * @param boolean $desc |
|
| 73 | + * @param array $columns |
|
| 74 | + * @return collection |
|
| 75 | + */ |
|
| 76 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
| 77 | + { |
|
| 78 | + $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
| 79 | + $conditionColumns = $this->model->getFillable(); |
|
| 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) . '%'); |
|
| 84 | - foreach ($conditionColumns as $column) |
|
| 85 | - { |
|
| 86 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 87 | - } |
|
| 88 | - foreach ($relations as $relation) |
|
| 89 | - { |
|
| 90 | - $relation = explode('.', $relation)[0]; |
|
| 91 | - if (\Core::$relation()) |
|
| 92 | - { |
|
| 93 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
| 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 | + foreach ($conditionColumns as $column) |
|
| 85 | + { |
|
| 86 | + $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 87 | + } |
|
| 88 | + foreach ($relations as $relation) |
|
| 89 | + { |
|
| 90 | + $relation = explode('.', $relation)[0]; |
|
| 91 | + if (\Core::$relation()) |
|
| 92 | + { |
|
| 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 | - $subConditionColumns = \Core::$relation()->model->getFillable(); |
|
| 98 | - $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 99 | - foreach ($subConditionColumns as $column) |
|
| 100 | - { |
|
| 101 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 102 | - } |
|
| 103 | - }); |
|
| 97 | + $subConditionColumns = \Core::$relation()->model->getFillable(); |
|
| 98 | + $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 99 | + foreach ($subConditionColumns as $column) |
|
| 100 | + { |
|
| 101 | + $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 102 | + } |
|
| 103 | + }); |
|
| 104 | 104 | |
| 105 | - }); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - }); |
|
| 105 | + }); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + }); |
|
| 109 | 109 | |
| 110 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
| 111 | - } |
|
| 110 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Fetch all records with relations from storage in pages. |
|
| 115 | - * |
|
| 116 | - * @param integer $perPage |
|
| 117 | - * @param array $relations |
|
| 118 | - * @param string $sortBy |
|
| 119 | - * @param boolean $desc |
|
| 120 | - * @param array $columns |
|
| 121 | - * @return collection |
|
| 122 | - */ |
|
| 123 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
| 124 | - { |
|
| 125 | - $sort = $desc ? 'desc' : 'asc'; |
|
| 126 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
| 127 | - } |
|
| 113 | + /** |
|
| 114 | + * Fetch all records with relations from storage in pages. |
|
| 115 | + * |
|
| 116 | + * @param integer $perPage |
|
| 117 | + * @param array $relations |
|
| 118 | + * @param string $sortBy |
|
| 119 | + * @param boolean $desc |
|
| 120 | + * @param array $columns |
|
| 121 | + * @return collection |
|
| 122 | + */ |
|
| 123 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
| 124 | + { |
|
| 125 | + $sort = $desc ? 'desc' : 'asc'; |
|
| 126 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Fetch all records with relations based on |
|
| 131 | - * the given condition from storage in pages. |
|
| 132 | - * |
|
| 133 | - * @param array $conditions array of conditions |
|
| 134 | - * @param integer $perPage |
|
| 135 | - * @param array $relations |
|
| 136 | - * @param string $sortBy |
|
| 137 | - * @param boolean $desc |
|
| 138 | - * @param array $columns |
|
| 139 | - * @return collection |
|
| 140 | - */ |
|
| 141 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
| 142 | - { |
|
| 143 | - unset($conditions['page']); |
|
| 144 | - $conditions = $this->constructConditions($conditions); |
|
| 145 | - $sort = $desc ? 'desc' : 'asc'; |
|
| 146 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
| 147 | - } |
|
| 129 | + /** |
|
| 130 | + * Fetch all records with relations based on |
|
| 131 | + * the given condition from storage in pages. |
|
| 132 | + * |
|
| 133 | + * @param array $conditions array of conditions |
|
| 134 | + * @param integer $perPage |
|
| 135 | + * @param array $relations |
|
| 136 | + * @param string $sortBy |
|
| 137 | + * @param boolean $desc |
|
| 138 | + * @param array $columns |
|
| 139 | + * @return collection |
|
| 140 | + */ |
|
| 141 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
| 142 | + { |
|
| 143 | + unset($conditions['page']); |
|
| 144 | + $conditions = $this->constructConditions($conditions); |
|
| 145 | + $sort = $desc ? 'desc' : 'asc'; |
|
| 146 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Save the given model to the storage. |
|
| 151 | - * |
|
| 152 | - * @param array $data |
|
| 153 | - * @param boolean $saveLog |
|
| 154 | - * @return object |
|
| 155 | - */ |
|
| 156 | - public function save(array $data, $saveLog = true) |
|
| 157 | - { |
|
| 158 | - $model = false; |
|
| 159 | - $modelClass = $this->model; |
|
| 160 | - $relations = []; |
|
| 161 | - $with = []; |
|
| 149 | + /** |
|
| 150 | + * Save the given model to the storage. |
|
| 151 | + * |
|
| 152 | + * @param array $data |
|
| 153 | + * @param boolean $saveLog |
|
| 154 | + * @return object |
|
| 155 | + */ |
|
| 156 | + public function save(array $data, $saveLog = true) |
|
| 157 | + { |
|
| 158 | + $model = false; |
|
| 159 | + $modelClass = $this->model; |
|
| 160 | + $relations = []; |
|
| 161 | + $with = []; |
|
| 162 | 162 | |
| 163 | - \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
| 164 | - /** |
|
| 165 | - * If the id is present in the data then select the model for updating, |
|
| 166 | - * else create new model. |
|
| 167 | - * @var array |
|
| 168 | - */ |
|
| 169 | - $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
| 170 | - if ( ! $model) |
|
| 171 | - { |
|
| 172 | - $error = $this->errorHandler->notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
| 173 | - abort($error['status'], $error['message']); |
|
| 174 | - } |
|
| 163 | + \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
| 164 | + /** |
|
| 165 | + * If the id is present in the data then select the model for updating, |
|
| 166 | + * else create new model. |
|
| 167 | + * @var array |
|
| 168 | + */ |
|
| 169 | + $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
| 170 | + if ( ! $model) |
|
| 171 | + { |
|
| 172 | + $error = $this->errorHandler->notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
| 173 | + abort($error['status'], $error['message']); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Construct the model object with the given data, |
|
| 178 | - * and if there is a relation add it to relations array, |
|
| 179 | - * then save the model. |
|
| 180 | - */ |
|
| 181 | - foreach ($data as $key => $value) |
|
| 182 | - { |
|
| 183 | - $relation = camel_case($key); |
|
| 184 | - if (method_exists($model, $relation)) |
|
| 185 | - { |
|
| 186 | - $with[] = $relation; |
|
| 187 | - if (class_basename($model->$relation) == 'Collection') |
|
| 188 | - { |
|
| 189 | - if ( ! $value || ! count($value)) |
|
| 190 | - { |
|
| 191 | - $relations[$relation] = 'delete'; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - if (is_array($value)) |
|
| 195 | - { |
|
| 196 | - foreach ($value as $attr => $val) |
|
| 197 | - { |
|
| 198 | - $relationBaseModel = \Core::$relation()->model; |
|
| 199 | - if (class_basename($model->$relation) == 'Collection') |
|
| 200 | - { |
|
| 201 | - $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
| 202 | - if ( ! $relationModel) |
|
| 203 | - { |
|
| 204 | - $error = $this->errorHandler->notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
| 205 | - abort($error['status'], $error['message']); |
|
| 206 | - } |
|
| 176 | + /** |
|
| 177 | + * Construct the model object with the given data, |
|
| 178 | + * and if there is a relation add it to relations array, |
|
| 179 | + * then save the model. |
|
| 180 | + */ |
|
| 181 | + foreach ($data as $key => $value) |
|
| 182 | + { |
|
| 183 | + $relation = camel_case($key); |
|
| 184 | + if (method_exists($model, $relation)) |
|
| 185 | + { |
|
| 186 | + $with[] = $relation; |
|
| 187 | + if (class_basename($model->$relation) == 'Collection') |
|
| 188 | + { |
|
| 189 | + if ( ! $value || ! count($value)) |
|
| 190 | + { |
|
| 191 | + $relations[$relation] = 'delete'; |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + if (is_array($value)) |
|
| 195 | + { |
|
| 196 | + foreach ($value as $attr => $val) |
|
| 197 | + { |
|
| 198 | + $relationBaseModel = \Core::$relation()->model; |
|
| 199 | + if (class_basename($model->$relation) == 'Collection') |
|
| 200 | + { |
|
| 201 | + $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
| 202 | + if ( ! $relationModel) |
|
| 203 | + { |
|
| 204 | + $error = $this->errorHandler->notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
| 205 | + abort($error['status'], $error['message']); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - foreach ($val as $attr => $val) |
|
| 209 | - { |
|
| 210 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 211 | - { |
|
| 212 | - $relationModel->$attr = $val; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - $relations[$relation][] = $relationModel; |
|
| 216 | - } |
|
| 217 | - else |
|
| 218 | - { |
|
| 219 | - if (gettype($val) !== 'object' && gettype($val) !== 'array') |
|
| 220 | - { |
|
| 221 | - $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
| 222 | - if ( ! $relationModel) |
|
| 223 | - { |
|
| 224 | - $error = $this->errorHandler->notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
| 225 | - abort($error['status'], $error['message']); |
|
| 226 | - } |
|
| 208 | + foreach ($val as $attr => $val) |
|
| 209 | + { |
|
| 210 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 211 | + { |
|
| 212 | + $relationModel->$attr = $val; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + $relations[$relation][] = $relationModel; |
|
| 216 | + } |
|
| 217 | + else |
|
| 218 | + { |
|
| 219 | + if (gettype($val) !== 'object' && gettype($val) !== 'array') |
|
| 220 | + { |
|
| 221 | + $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
| 222 | + if ( ! $relationModel) |
|
| 223 | + { |
|
| 224 | + $error = $this->errorHandler->notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
| 225 | + abort($error['status'], $error['message']); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - if (array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 229 | - { |
|
| 230 | - $relationModel->$attr = $val; |
|
| 231 | - $relations[$relation] = $relationModel; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - else if (array_search($key, $model->getFillable(), true) !== false) |
|
| 239 | - { |
|
| 240 | - $model->$key = $value; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - $model->save(); |
|
| 228 | + if (array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 229 | + { |
|
| 230 | + $relationModel->$attr = $val; |
|
| 231 | + $relations[$relation] = $relationModel; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + else if (array_search($key, $model->getFillable(), true) !== false) |
|
| 239 | + { |
|
| 240 | + $model->$key = $value; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + $model->save(); |
|
| 244 | 244 | |
| 245 | - foreach ($relations as $key => $value) |
|
| 246 | - { |
|
| 247 | - if ($value == 'delete' && $model->$key()->count()) |
|
| 248 | - { |
|
| 249 | - $model->$key()->delete(); |
|
| 250 | - } |
|
| 251 | - else if (gettype($value) == 'array') |
|
| 252 | - { |
|
| 253 | - $ids = []; |
|
| 254 | - foreach ($value as $val) |
|
| 255 | - { |
|
| 256 | - switch (class_basename($model->$key())) |
|
| 257 | - { |
|
| 258 | - case 'HasMany': |
|
| 259 | - $foreignKeyName = explode('.', $model->$key()->getForeignKey())[1]; |
|
| 260 | - $val->$foreignKeyName = $model->id; |
|
| 261 | - $val->save(); |
|
| 262 | - $ids[] = $val->id; |
|
| 263 | - break; |
|
| 245 | + foreach ($relations as $key => $value) |
|
| 246 | + { |
|
| 247 | + if ($value == 'delete' && $model->$key()->count()) |
|
| 248 | + { |
|
| 249 | + $model->$key()->delete(); |
|
| 250 | + } |
|
| 251 | + else if (gettype($value) == 'array') |
|
| 252 | + { |
|
| 253 | + $ids = []; |
|
| 254 | + foreach ($value as $val) |
|
| 255 | + { |
|
| 256 | + switch (class_basename($model->$key())) |
|
| 257 | + { |
|
| 258 | + case 'HasMany': |
|
| 259 | + $foreignKeyName = explode('.', $model->$key()->getForeignKey())[1]; |
|
| 260 | + $val->$foreignKeyName = $model->id; |
|
| 261 | + $val->save(); |
|
| 262 | + $ids[] = $val->id; |
|
| 263 | + break; |
|
| 264 | 264 | |
| 265 | - case 'BelongsToMany': |
|
| 266 | - $val->save(); |
|
| 267 | - $ids[] = $val->id; |
|
| 268 | - break; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - switch (class_basename($model->$key())) |
|
| 272 | - { |
|
| 273 | - case 'HasMany': |
|
| 274 | - $model->$key()->whereNotIn('id', $ids)->delete(); |
|
| 275 | - break; |
|
| 265 | + case 'BelongsToMany': |
|
| 266 | + $val->save(); |
|
| 267 | + $ids[] = $val->id; |
|
| 268 | + break; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + switch (class_basename($model->$key())) |
|
| 272 | + { |
|
| 273 | + case 'HasMany': |
|
| 274 | + $model->$key()->whereNotIn('id', $ids)->delete(); |
|
| 275 | + break; |
|
| 276 | 276 | |
| 277 | - case 'BelongsToMany': |
|
| 278 | - $model->$key()->detach(); |
|
| 279 | - $model->$key()->attach($ids); |
|
| 280 | - break; |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - else |
|
| 284 | - { |
|
| 285 | - switch (class_basename($model->$key())) |
|
| 286 | - { |
|
| 287 | - case 'BelongsTo': |
|
| 288 | - $value->save(); |
|
| 289 | - $model->$key()->associate($value); |
|
| 290 | - $model->save(); |
|
| 291 | - break; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - $saveLog ? $this->logs->saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false; |
|
| 296 | - }); |
|
| 277 | + case 'BelongsToMany': |
|
| 278 | + $model->$key()->detach(); |
|
| 279 | + $model->$key()->attach($ids); |
|
| 280 | + break; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + else |
|
| 284 | + { |
|
| 285 | + switch (class_basename($model->$key())) |
|
| 286 | + { |
|
| 287 | + case 'BelongsTo': |
|
| 288 | + $value->save(); |
|
| 289 | + $model->$key()->associate($value); |
|
| 290 | + $model->save(); |
|
| 291 | + break; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + $saveLog ? $this->logs->saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false; |
|
| 296 | + }); |
|
| 297 | 297 | |
| 298 | - $this->afterSave($model, $relations); |
|
| 298 | + $this->afterSave($model, $relations); |
|
| 299 | 299 | |
| 300 | - return $this->find($model->id, $with); |
|
| 301 | - } |
|
| 300 | + return $this->find($model->id, $with); |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - /** |
|
| 304 | - * Save the given models to the storage. |
|
| 305 | - * |
|
| 306 | - * @param array $data |
|
| 307 | - * @return object |
|
| 308 | - */ |
|
| 309 | - public function saveMany(array $data) |
|
| 310 | - { |
|
| 311 | - $result = []; |
|
| 312 | - \DB::transaction(function () use (&$result, $data) { |
|
| 313 | - foreach ($data as $key => $value) |
|
| 314 | - { |
|
| 315 | - $result[] = $this->save($value); |
|
| 316 | - } |
|
| 317 | - }); |
|
| 318 | - return $result; |
|
| 319 | - } |
|
| 303 | + /** |
|
| 304 | + * Save the given models to the storage. |
|
| 305 | + * |
|
| 306 | + * @param array $data |
|
| 307 | + * @return object |
|
| 308 | + */ |
|
| 309 | + public function saveMany(array $data) |
|
| 310 | + { |
|
| 311 | + $result = []; |
|
| 312 | + \DB::transaction(function () use (&$result, $data) { |
|
| 313 | + foreach ($data as $key => $value) |
|
| 314 | + { |
|
| 315 | + $result[] = $this->save($value); |
|
| 316 | + } |
|
| 317 | + }); |
|
| 318 | + return $result; |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - /** |
|
| 322 | - * Update record in the storage based on the given |
|
| 323 | - * condition. |
|
| 324 | - * |
|
| 325 | - * @param [type] $value condition value |
|
| 326 | - * @param array $data |
|
| 327 | - * @param string $attribute condition column name |
|
| 328 | - * @return void |
|
| 329 | - */ |
|
| 330 | - public function update($value, array $data, $attribute = 'id', $saveLog = true) |
|
| 331 | - { |
|
| 332 | - if ($attribute == 'id') |
|
| 333 | - { |
|
| 334 | - $model = $this->model->lockForUpdate()->find($value); |
|
| 335 | - $model ? $model->update($data) : 0; |
|
| 336 | - $saveLog ? $this->logs->saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
| 337 | - } |
|
| 338 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
| 339 | - $model->update($data); |
|
| 340 | - $saveLog ? $this->logs->saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
| 341 | - }); |
|
| 342 | - } |
|
| 321 | + /** |
|
| 322 | + * Update record in the storage based on the given |
|
| 323 | + * condition. |
|
| 324 | + * |
|
| 325 | + * @param [type] $value condition value |
|
| 326 | + * @param array $data |
|
| 327 | + * @param string $attribute condition column name |
|
| 328 | + * @return void |
|
| 329 | + */ |
|
| 330 | + public function update($value, array $data, $attribute = 'id', $saveLog = true) |
|
| 331 | + { |
|
| 332 | + if ($attribute == 'id') |
|
| 333 | + { |
|
| 334 | + $model = $this->model->lockForUpdate()->find($value); |
|
| 335 | + $model ? $model->update($data) : 0; |
|
| 336 | + $saveLog ? $this->logs->saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
| 337 | + } |
|
| 338 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
| 339 | + $model->update($data); |
|
| 340 | + $saveLog ? $this->logs->saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
| 341 | + }); |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - /** |
|
| 345 | - * Delete record from the storage based on the given |
|
| 346 | - * condition. |
|
| 347 | - * |
|
| 348 | - * @param [type] $value condition value |
|
| 349 | - * @param string $attribute condition column name |
|
| 350 | - * @return void |
|
| 351 | - */ |
|
| 352 | - public function delete($value, $attribute = 'id', $saveLog = true) |
|
| 353 | - { |
|
| 354 | - if ($attribute == 'id') |
|
| 355 | - { |
|
| 356 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 357 | - $model = $this->model->lockForUpdate()->find($value); |
|
| 358 | - $model->delete(); |
|
| 359 | - $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
| 360 | - }); |
|
| 361 | - } |
|
| 362 | - else |
|
| 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){ |
|
| 366 | - $model->delete(); |
|
| 367 | - $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
| 368 | - }); |
|
| 369 | - }); |
|
| 370 | - } |
|
| 371 | - } |
|
| 344 | + /** |
|
| 345 | + * Delete record from the storage based on the given |
|
| 346 | + * condition. |
|
| 347 | + * |
|
| 348 | + * @param [type] $value condition value |
|
| 349 | + * @param string $attribute condition column name |
|
| 350 | + * @return void |
|
| 351 | + */ |
|
| 352 | + public function delete($value, $attribute = 'id', $saveLog = true) |
|
| 353 | + { |
|
| 354 | + if ($attribute == 'id') |
|
| 355 | + { |
|
| 356 | + \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 357 | + $model = $this->model->lockForUpdate()->find($value); |
|
| 358 | + $model->delete(); |
|
| 359 | + $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
| 360 | + }); |
|
| 361 | + } |
|
| 362 | + else |
|
| 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){ |
|
| 366 | + $model->delete(); |
|
| 367 | + $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
| 368 | + }); |
|
| 369 | + }); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * Fetch records from the storage based on the given |
|
| 375 | - * id. |
|
| 376 | - * |
|
| 377 | - * @param integer $id |
|
| 378 | - * @param array $relations |
|
| 379 | - * @param array $columns |
|
| 380 | - * @return object |
|
| 381 | - */ |
|
| 382 | - public function find($id, $relations = [], $columns = array('*')) |
|
| 383 | - { |
|
| 384 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
|
| 385 | - } |
|
| 373 | + /** |
|
| 374 | + * Fetch records from the storage based on the given |
|
| 375 | + * id. |
|
| 376 | + * |
|
| 377 | + * @param integer $id |
|
| 378 | + * @param array $relations |
|
| 379 | + * @param array $columns |
|
| 380 | + * @return object |
|
| 381 | + */ |
|
| 382 | + public function find($id, $relations = [], $columns = array('*')) |
|
| 383 | + { |
|
| 384 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | - /** |
|
| 388 | - * Fetch records from the storage based on the given |
|
| 389 | - * condition. |
|
| 390 | - * |
|
| 391 | - * @param array $conditions array of conditions |
|
| 392 | - * @param array $relations |
|
| 393 | - * @param string $sortBy |
|
| 394 | - * @param boolean $desc |
|
| 395 | - * @param array $columns |
|
| 396 | - * @return collection |
|
| 397 | - */ |
|
| 398 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
| 399 | - { |
|
| 400 | - $conditions = $this->constructConditions($conditions); |
|
| 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); |
|
| 403 | - } |
|
| 387 | + /** |
|
| 388 | + * Fetch records from the storage based on the given |
|
| 389 | + * condition. |
|
| 390 | + * |
|
| 391 | + * @param array $conditions array of conditions |
|
| 392 | + * @param array $relations |
|
| 393 | + * @param string $sortBy |
|
| 394 | + * @param boolean $desc |
|
| 395 | + * @param array $columns |
|
| 396 | + * @return collection |
|
| 397 | + */ |
|
| 398 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
| 399 | + { |
|
| 400 | + $conditions = $this->constructConditions($conditions); |
|
| 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); |
|
| 403 | + } |
|
| 404 | 404 | |
| 405 | - /** |
|
| 406 | - * Fetch the first record from the storage based on the given |
|
| 407 | - * condition. |
|
| 408 | - * |
|
| 409 | - * @param array $conditions array of conditions |
|
| 410 | - * @param array $relations |
|
| 411 | - * @param array $colunmns |
|
| 412 | - * @return object |
|
| 413 | - */ |
|
| 414 | - public function first($conditions, $relations = [], $columns = array('*')) |
|
| 415 | - { |
|
| 416 | - $conditions = $this->constructConditions($conditions); |
|
| 417 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
| 418 | - } |
|
| 405 | + /** |
|
| 406 | + * Fetch the first record from the storage based on the given |
|
| 407 | + * condition. |
|
| 408 | + * |
|
| 409 | + * @param array $conditions array of conditions |
|
| 410 | + * @param array $relations |
|
| 411 | + * @param array $colunmns |
|
| 412 | + * @return object |
|
| 413 | + */ |
|
| 414 | + public function first($conditions, $relations = [], $columns = array('*')) |
|
| 415 | + { |
|
| 416 | + $conditions = $this->constructConditions($conditions); |
|
| 417 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - /** |
|
| 421 | - * Build the conditions recursively for the retrieving methods. |
|
| 422 | - * @param array $conditions |
|
| 423 | - * @return array |
|
| 424 | - */ |
|
| 425 | - protected function constructConditions($conditions) |
|
| 426 | - { |
|
| 427 | - $conditionString = ''; |
|
| 428 | - $conditionValues = []; |
|
| 429 | - foreach ($conditions as $key => $value) |
|
| 430 | - { |
|
| 431 | - if ($key == 'and') |
|
| 432 | - { |
|
| 433 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
| 434 | - $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
| 435 | - } |
|
| 436 | - else if ($key == 'or') |
|
| 437 | - { |
|
| 438 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
| 439 | - $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
| 440 | - } |
|
| 441 | - else |
|
| 442 | - { |
|
| 443 | - $conditionString .= $key . '=? {op} '; |
|
| 444 | - $conditionValues[] = $value; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
| 448 | - return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
| 449 | - } |
|
| 420 | + /** |
|
| 421 | + * Build the conditions recursively for the retrieving methods. |
|
| 422 | + * @param array $conditions |
|
| 423 | + * @return array |
|
| 424 | + */ |
|
| 425 | + protected function constructConditions($conditions) |
|
| 426 | + { |
|
| 427 | + $conditionString = ''; |
|
| 428 | + $conditionValues = []; |
|
| 429 | + foreach ($conditions as $key => $value) |
|
| 430 | + { |
|
| 431 | + if ($key == 'and') |
|
| 432 | + { |
|
| 433 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
| 434 | + $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
| 435 | + } |
|
| 436 | + else if ($key == 'or') |
|
| 437 | + { |
|
| 438 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
| 439 | + $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
| 440 | + } |
|
| 441 | + else |
|
| 442 | + { |
|
| 443 | + $conditionString .= $key . '=? {op} '; |
|
| 444 | + $conditionValues[] = $value; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
| 448 | + return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
| 449 | + } |
|
| 450 | 450 | |
| 451 | - /** |
|
| 452 | - * Abstract method that is called in after |
|
| 453 | - * the save method finish. |
|
| 454 | - * |
|
| 455 | - * @param object $model |
|
| 456 | - * @param array $relations |
|
| 457 | - * @return void |
|
| 458 | - */ |
|
| 459 | - protected function afterSave($model, $relations) |
|
| 460 | - { |
|
| 461 | - return false; |
|
| 462 | - } |
|
| 451 | + /** |
|
| 452 | + * Abstract method that is called in after |
|
| 453 | + * the save method finish. |
|
| 454 | + * |
|
| 455 | + * @param object $model |
|
| 456 | + * @param array $relations |
|
| 457 | + * @return void |
|
| 458 | + */ |
|
| 459 | + protected function afterSave($model, $relations) |
|
| 460 | + { |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - /** |
|
| 465 | - * Abstract method that return the necessary |
|
| 466 | - * information (full model namespace) |
|
| 467 | - * needed to preform the previous actions. |
|
| 468 | - * |
|
| 469 | - * @return string |
|
| 470 | - */ |
|
| 471 | - abstract protected function getModel(); |
|
| 464 | + /** |
|
| 465 | + * Abstract method that return the necessary |
|
| 466 | + * information (full model namespace) |
|
| 467 | + * needed to preform the previous actions. |
|
| 468 | + * |
|
| 469 | + * @return string |
|
| 470 | + */ |
|
| 471 | + abstract protected function getModel(); |
|
| 472 | 472 | } |
| 473 | 473 | \ No newline at end of file |
@@ -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; |
@@ -54,9 +54,7 @@ discard block |
||
| 54 | 54 | /** |
| 55 | 55 | * Fetch all records with relations from model repository. |
| 56 | 56 | * |
| 57 | - * @param string $sortBy |
|
| 58 | - * @param boolean $desc |
|
| 59 | - * @return \Illuminate\Http\Response |
|
| 57 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 60 | 58 | */ |
| 61 | 59 | public function getIndex() |
| 62 | 60 | { |
@@ -71,7 +69,7 @@ discard block |
||
| 71 | 69 | * Fetch the single object with relations from model repository. |
| 72 | 70 | * |
| 73 | 71 | * @param integer $id |
| 74 | - * @return \Illuminate\Http\Response |
|
| 72 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 75 | 73 | */ |
| 76 | 74 | public function getFind($id) |
| 77 | 75 | { |
@@ -89,8 +87,8 @@ discard block |
||
| 89 | 87 | * @param string $query |
| 90 | 88 | * @param integer $perPage |
| 91 | 89 | * @param string $sortBy |
| 92 | - * @param boolean $desc |
|
| 93 | - * @return \Illuminate\Http\Response |
|
| 90 | + * @param integer $desc |
|
| 91 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 94 | 92 | */ |
| 95 | 93 | public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
| 96 | 94 | { |
@@ -107,8 +105,8 @@ discard block |
||
| 107 | 105 | * |
| 108 | 106 | * @param \Illuminate\Http\Request $request |
| 109 | 107 | * @param string $sortBy |
| 110 | - * @param boolean $desc |
|
| 111 | - * @return \Illuminate\Http\Response |
|
| 108 | + * @param integer $desc |
|
| 109 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 112 | 110 | */ |
| 113 | 111 | public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
| 114 | 112 | { |
@@ -124,7 +122,7 @@ discard block |
||
| 124 | 122 | * condition. |
| 125 | 123 | * |
| 126 | 124 | * @param \Illuminate\Http\Request $request |
| 127 | - * @return \Illuminate\Http\Response |
|
| 125 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 128 | 126 | */ |
| 129 | 127 | public function postFirst(Request $request) |
| 130 | 128 | { |
@@ -140,8 +138,8 @@ discard block |
||
| 140 | 138 | * |
| 141 | 139 | * @param integer $perPage |
| 142 | 140 | * @param string $sortBy |
| 143 | - * @param boolean $desc |
|
| 144 | - * @return \Illuminate\Http\Response |
|
| 141 | + * @param integer $desc |
|
| 142 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 145 | 143 | */ |
| 146 | 144 | public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
| 147 | 145 | { |
@@ -159,8 +157,8 @@ discard block |
||
| 159 | 157 | * @param \Illuminate\Http\Request $request |
| 160 | 158 | * @param integer $perPage |
| 161 | 159 | * @param string $sortBy |
| 162 | - * @param boolean $desc |
|
| 163 | - * @return \Illuminate\Http\Response |
|
| 160 | + * @param integer $desc |
|
| 161 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 164 | 162 | */ |
| 165 | 163 | public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
| 166 | 164 | { |
@@ -175,7 +173,7 @@ discard block |
||
| 175 | 173 | * Save the given model to repository. |
| 176 | 174 | * |
| 177 | 175 | * @param \Illuminate\Http\Request $request |
| 178 | - * @return \Illuminate\Http\Response |
|
| 176 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 179 | 177 | */ |
| 180 | 178 | public function postSave(Request $request) |
| 181 | 179 | { |
@@ -208,7 +206,7 @@ discard block |
||
| 208 | 206 | * Delete by the given id from model repository. |
| 209 | 207 | * |
| 210 | 208 | * @param integer $id |
| 211 | - * @return \Illuminate\Http\Response |
|
| 209 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 212 | 210 | */ |
| 213 | 211 | public function getDelete($id) |
| 214 | 212 | { |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
| 48 | 48 | |
| 49 | 49 | $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
| 50 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 50 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
| 51 | 51 | $this->checkPermission(explode('_', snake_case($route))[1]); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -189,8 +189,7 @@ discard block |
||
| 189 | 189 | if ($request->has('id')) |
| 190 | 190 | { |
| 191 | 191 | $rule = str_replace('{id}', $request->get('id'), $rule); |
| 192 | - } |
|
| 193 | - else |
|
| 192 | + } else |
|
| 194 | 193 | { |
| 195 | 194 | $rule = str_replace(',{id}', '', $rule); |
| 196 | 195 | } |
@@ -231,15 +230,13 @@ discard block |
||
| 231 | 230 | { |
| 232 | 231 | $error = $this->errorHandler->notFound('method'); |
| 233 | 232 | abort($error['status'], $error['message']); |
| 234 | - } |
|
| 235 | - else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 233 | + } else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 236 | 234 | { |
| 237 | 235 | if ( ! \Auth::check()) |
| 238 | 236 | { |
| 239 | 237 | $error = $this->errorHandler->unAuthorized(); |
| 240 | 238 | abort($error['status'], $error['message']); |
| 241 | - } |
|
| 242 | - else if ( ! in_array($permission, $this->skipPermissionCheck) && |
|
| 239 | + } else if ( ! in_array($permission, $this->skipPermissionCheck) && |
|
| 243 | 240 | ! \Core::users()->can($permission, $this->model)) |
| 244 | 241 | { |
| 245 | 242 | $error = $this->errorHandler->noPermissions(); |
@@ -9,243 +9,243 @@ |
||
| 9 | 9 | |
| 10 | 10 | class BaseApiController extends Controller |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * The errorHandler implementation. |
|
| 14 | - * |
|
| 15 | - * @var errorHandler |
|
| 16 | - */ |
|
| 17 | - protected $errorHandler; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The config implementation. |
|
| 21 | - * |
|
| 22 | - * @var config |
|
| 23 | - */ |
|
| 24 | - protected $config; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * The model implementation. |
|
| 28 | - * |
|
| 29 | - * @var model |
|
| 30 | - */ |
|
| 31 | - protected $model; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Create new BaseApiController instance. |
|
| 35 | - * |
|
| 36 | - * @param errorHandler |
|
| 37 | - */ |
|
| 38 | - public function __construct(ErrorHandler $errorHandler, CoreConfig $config) |
|
| 39 | - { |
|
| 40 | - \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
| 12 | + /** |
|
| 13 | + * The errorHandler implementation. |
|
| 14 | + * |
|
| 15 | + * @var errorHandler |
|
| 16 | + */ |
|
| 17 | + protected $errorHandler; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The config implementation. |
|
| 21 | + * |
|
| 22 | + * @var config |
|
| 23 | + */ |
|
| 24 | + protected $config; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * The model implementation. |
|
| 28 | + * |
|
| 29 | + * @var model |
|
| 30 | + */ |
|
| 31 | + protected $model; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Create new BaseApiController instance. |
|
| 35 | + * |
|
| 36 | + * @param errorHandler |
|
| 37 | + */ |
|
| 38 | + public function __construct(ErrorHandler $errorHandler, CoreConfig $config) |
|
| 39 | + { |
|
| 40 | + \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
| 41 | 41 | |
| 42 | - $this->errorHandler = $errorHandler; |
|
| 43 | - $this->config = $config->getConfig(); |
|
| 42 | + $this->errorHandler = $errorHandler; |
|
| 43 | + $this->config = $config->getConfig(); |
|
| 44 | 44 | |
| 45 | - $this->model = property_exists($this, 'model') ? $this->model : false; |
|
| 46 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
| 47 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
| 48 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
| 45 | + $this->model = property_exists($this, 'model') ? $this->model : false; |
|
| 46 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
| 47 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
| 48 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
| 49 | 49 | |
| 50 | - $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
| 51 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 52 | - $this->checkPermission(explode('_', snake_case($route))[1]); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Fetch all records with relations from model repository. |
|
| 57 | - * |
|
| 58 | - * @param string $sortBy |
|
| 59 | - * @param boolean $desc |
|
| 60 | - * @return \Illuminate\Http\Response |
|
| 61 | - */ |
|
| 62 | - public function getIndex() |
|
| 63 | - { |
|
| 64 | - if ($this->model) |
|
| 65 | - { |
|
| 66 | - $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
| 67 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Fetch the single object with relations from model repository. |
|
| 73 | - * |
|
| 74 | - * @param integer $id |
|
| 75 | - * @return \Illuminate\Http\Response |
|
| 76 | - */ |
|
| 77 | - public function getFind($id) |
|
| 78 | - { |
|
| 79 | - if ($this->model) |
|
| 80 | - { |
|
| 81 | - $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
| 82 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Paginate all records with relations from model repository |
|
| 88 | - * that matche the given query. |
|
| 89 | - * |
|
| 90 | - * @param string $query |
|
| 91 | - * @param integer $perPage |
|
| 92 | - * @param string $sortBy |
|
| 93 | - * @param boolean $desc |
|
| 94 | - * @return \Illuminate\Http\Response |
|
| 95 | - */ |
|
| 96 | - public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 97 | - { |
|
| 98 | - if ($this->model) |
|
| 99 | - { |
|
| 100 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
| 101 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Fetch records from the storage based on the given |
|
| 107 | - * condition. |
|
| 108 | - * |
|
| 109 | - * @param \Illuminate\Http\Request $request |
|
| 110 | - * @param string $sortBy |
|
| 111 | - * @param boolean $desc |
|
| 112 | - * @return \Illuminate\Http\Response |
|
| 113 | - */ |
|
| 114 | - public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
| 115 | - { |
|
| 116 | - if ($this->model) |
|
| 117 | - { |
|
| 118 | - $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
| 119 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Fetch the first record from the storage based on the given |
|
| 125 | - * condition. |
|
| 126 | - * |
|
| 127 | - * @param \Illuminate\Http\Request $request |
|
| 128 | - * @return \Illuminate\Http\Response |
|
| 129 | - */ |
|
| 130 | - public function postFirst(Request $request) |
|
| 131 | - { |
|
| 132 | - if ($this->model) |
|
| 133 | - { |
|
| 134 | - $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
| 135 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Paginate all records with relations from model repository. |
|
| 141 | - * |
|
| 142 | - * @param integer $perPage |
|
| 143 | - * @param string $sortBy |
|
| 144 | - * @param boolean $desc |
|
| 145 | - * @return \Illuminate\Http\Response |
|
| 146 | - */ |
|
| 147 | - public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 148 | - { |
|
| 149 | - if ($this->model) |
|
| 150 | - { |
|
| 151 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
| 152 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Fetch all records with relations based on |
|
| 158 | - * the given condition from storage in pages. |
|
| 159 | - * |
|
| 160 | - * @param \Illuminate\Http\Request $request |
|
| 161 | - * @param integer $perPage |
|
| 162 | - * @param string $sortBy |
|
| 163 | - * @param boolean $desc |
|
| 164 | - * @return \Illuminate\Http\Response |
|
| 165 | - */ |
|
| 166 | - public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 167 | - { |
|
| 168 | - if ($this->model) |
|
| 169 | - { |
|
| 170 | - $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
| 171 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Save the given model to repository. |
|
| 177 | - * |
|
| 178 | - * @param \Illuminate\Http\Request $request |
|
| 179 | - * @return \Illuminate\Http\Response |
|
| 180 | - */ |
|
| 181 | - public function postSave(Request $request) |
|
| 182 | - { |
|
| 183 | - foreach ($this->validationRules as &$rule) |
|
| 184 | - { |
|
| 185 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
| 186 | - { |
|
| 187 | - $rule .= ',deleted_at,NULL'; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if ($request->has('id')) |
|
| 191 | - { |
|
| 192 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
| 193 | - } |
|
| 194 | - else |
|
| 195 | - { |
|
| 196 | - $rule = str_replace(',{id}', '', $rule); |
|
| 197 | - } |
|
| 198 | - } |
|
| 50 | + $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
| 51 | + $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 52 | + $this->checkPermission(explode('_', snake_case($route))[1]); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Fetch all records with relations from model repository. |
|
| 57 | + * |
|
| 58 | + * @param string $sortBy |
|
| 59 | + * @param boolean $desc |
|
| 60 | + * @return \Illuminate\Http\Response |
|
| 61 | + */ |
|
| 62 | + public function getIndex() |
|
| 63 | + { |
|
| 64 | + if ($this->model) |
|
| 65 | + { |
|
| 66 | + $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
| 67 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Fetch the single object with relations from model repository. |
|
| 73 | + * |
|
| 74 | + * @param integer $id |
|
| 75 | + * @return \Illuminate\Http\Response |
|
| 76 | + */ |
|
| 77 | + public function getFind($id) |
|
| 78 | + { |
|
| 79 | + if ($this->model) |
|
| 80 | + { |
|
| 81 | + $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
| 82 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Paginate all records with relations from model repository |
|
| 88 | + * that matche the given query. |
|
| 89 | + * |
|
| 90 | + * @param string $query |
|
| 91 | + * @param integer $perPage |
|
| 92 | + * @param string $sortBy |
|
| 93 | + * @param boolean $desc |
|
| 94 | + * @return \Illuminate\Http\Response |
|
| 95 | + */ |
|
| 96 | + public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 97 | + { |
|
| 98 | + if ($this->model) |
|
| 99 | + { |
|
| 100 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
| 101 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Fetch records from the storage based on the given |
|
| 107 | + * condition. |
|
| 108 | + * |
|
| 109 | + * @param \Illuminate\Http\Request $request |
|
| 110 | + * @param string $sortBy |
|
| 111 | + * @param boolean $desc |
|
| 112 | + * @return \Illuminate\Http\Response |
|
| 113 | + */ |
|
| 114 | + public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
| 115 | + { |
|
| 116 | + if ($this->model) |
|
| 117 | + { |
|
| 118 | + $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
| 119 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Fetch the first record from the storage based on the given |
|
| 125 | + * condition. |
|
| 126 | + * |
|
| 127 | + * @param \Illuminate\Http\Request $request |
|
| 128 | + * @return \Illuminate\Http\Response |
|
| 129 | + */ |
|
| 130 | + public function postFirst(Request $request) |
|
| 131 | + { |
|
| 132 | + if ($this->model) |
|
| 133 | + { |
|
| 134 | + $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
| 135 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Paginate all records with relations from model repository. |
|
| 141 | + * |
|
| 142 | + * @param integer $perPage |
|
| 143 | + * @param string $sortBy |
|
| 144 | + * @param boolean $desc |
|
| 145 | + * @return \Illuminate\Http\Response |
|
| 146 | + */ |
|
| 147 | + public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 148 | + { |
|
| 149 | + if ($this->model) |
|
| 150 | + { |
|
| 151 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
| 152 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Fetch all records with relations based on |
|
| 158 | + * the given condition from storage in pages. |
|
| 159 | + * |
|
| 160 | + * @param \Illuminate\Http\Request $request |
|
| 161 | + * @param integer $perPage |
|
| 162 | + * @param string $sortBy |
|
| 163 | + * @param boolean $desc |
|
| 164 | + * @return \Illuminate\Http\Response |
|
| 165 | + */ |
|
| 166 | + public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 167 | + { |
|
| 168 | + if ($this->model) |
|
| 169 | + { |
|
| 170 | + $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
| 171 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Save the given model to repository. |
|
| 177 | + * |
|
| 178 | + * @param \Illuminate\Http\Request $request |
|
| 179 | + * @return \Illuminate\Http\Response |
|
| 180 | + */ |
|
| 181 | + public function postSave(Request $request) |
|
| 182 | + { |
|
| 183 | + foreach ($this->validationRules as &$rule) |
|
| 184 | + { |
|
| 185 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
| 186 | + { |
|
| 187 | + $rule .= ',deleted_at,NULL'; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if ($request->has('id')) |
|
| 191 | + { |
|
| 192 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
| 193 | + } |
|
| 194 | + else |
|
| 195 | + { |
|
| 196 | + $rule = str_replace(',{id}', '', $rule); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - $this->validate($request, $this->validationRules); |
|
| 201 | - |
|
| 202 | - if ($this->model) |
|
| 203 | - { |
|
| 204 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Delete by the given id from model repository. |
|
| 210 | - * |
|
| 211 | - * @param integer $id |
|
| 212 | - * @return \Illuminate\Http\Response |
|
| 213 | - */ |
|
| 214 | - public function getDelete($id) |
|
| 215 | - { |
|
| 216 | - if ($this->model) |
|
| 217 | - { |
|
| 218 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Check if the logged in user can do the given permission. |
|
| 224 | - * |
|
| 225 | - * @param string $permission |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - private function checkPermission($permission) |
|
| 229 | - { |
|
| 230 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
| 231 | - if ($permission == 'method') |
|
| 232 | - { |
|
| 233 | - $error = $this->errorHandler->notFound('method'); |
|
| 234 | - abort($error['status'], $error['message']); |
|
| 235 | - } |
|
| 236 | - else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 237 | - { |
|
| 238 | - if ( ! \Auth::check()) |
|
| 239 | - { |
|
| 240 | - $error = $this->errorHandler->unAuthorized(); |
|
| 241 | - abort($error['status'], $error['message']); |
|
| 242 | - } |
|
| 243 | - else if ( ! in_array($permission, $this->skipPermissionCheck) && |
|
| 244 | - ! \Core::users()->can($permission, $this->model)) |
|
| 245 | - { |
|
| 246 | - $error = $this->errorHandler->noPermissions(); |
|
| 247 | - abort($error['status'], $error['message']); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - } |
|
| 200 | + $this->validate($request, $this->validationRules); |
|
| 201 | + |
|
| 202 | + if ($this->model) |
|
| 203 | + { |
|
| 204 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Delete by the given id from model repository. |
|
| 210 | + * |
|
| 211 | + * @param integer $id |
|
| 212 | + * @return \Illuminate\Http\Response |
|
| 213 | + */ |
|
| 214 | + public function getDelete($id) |
|
| 215 | + { |
|
| 216 | + if ($this->model) |
|
| 217 | + { |
|
| 218 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Check if the logged in user can do the given permission. |
|
| 224 | + * |
|
| 225 | + * @param string $permission |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + private function checkPermission($permission) |
|
| 229 | + { |
|
| 230 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
| 231 | + if ($permission == 'method') |
|
| 232 | + { |
|
| 233 | + $error = $this->errorHandler->notFound('method'); |
|
| 234 | + abort($error['status'], $error['message']); |
|
| 235 | + } |
|
| 236 | + else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 237 | + { |
|
| 238 | + if ( ! \Auth::check()) |
|
| 239 | + { |
|
| 240 | + $error = $this->errorHandler->unAuthorized(); |
|
| 241 | + abort($error['status'], $error['message']); |
|
| 242 | + } |
|
| 243 | + else if ( ! in_array($permission, $this->skipPermissionCheck) && |
|
| 244 | + ! \Core::users()->can($permission, $this->model)) |
|
| 245 | + { |
|
| 246 | + $error = $this->errorHandler->noPermissions(); |
|
| 247 | + abort($error['status'], $error['message']); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | 251 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * |
| 8 | 8 | * @param array $relations |
| 9 | 9 | * @param array $sortBy |
| 10 | - * @param array $desc |
|
| 10 | + * @param integer $desc |
|
| 11 | 11 | * @param array $columns |
| 12 | 12 | * @return collection |
| 13 | 13 | */ |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param integer $perPage |
| 22 | 22 | * @param array $relations |
| 23 | 23 | * @param array $sortBy |
| 24 | - * @param array $desc |
|
| 24 | + * @param integer $desc |
|
| 25 | 25 | * @param array $columns |
| 26 | 26 | * @return collection |
| 27 | 27 | */ |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param integer $perPage |
| 34 | 34 | * @param array $relations |
| 35 | 35 | * @param array $sortBy |
| 36 | - * @param array $desc |
|
| 36 | + * @param integer $desc |
|
| 37 | 37 | * @param array $columns |
| 38 | 38 | * @return collection |
| 39 | 39 | */ |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param integer $perPage |
| 48 | 48 | * @param array $relations |
| 49 | 49 | * @param array $sortBy |
| 50 | - * @param array $desc |
|
| 50 | + * @param integer $desc |
|
| 51 | 51 | * @param array $columns |
| 52 | 52 | * @return collection |
| 53 | 53 | */ |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param array $conditions array of conditions |
| 110 | 110 | * @param array $relations |
| 111 | 111 | * @param array $sortBy |
| 112 | - * @param array $desc |
|
| 112 | + * @param integer $desc |
|
| 113 | 113 | * @param array $columns |
| 114 | 114 | * @return collection |
| 115 | 115 | */ |
@@ -120,7 +120,6 @@ discard block |
||
| 120 | 120 | * condition. |
| 121 | 121 | * |
| 122 | 122 | * @param array $conditions array of conditions |
| 123 | - * @param [type] $value condition value |
|
| 124 | 123 | * @param array $relations |
| 125 | 124 | * @param array $columns |
| 126 | 125 | * @return object |
@@ -3,127 +3,127 @@ |
||
| 3 | 3 | interface RepositoryInterface |
| 4 | 4 | { |
| 5 | 5 | /** |
| 6 | - * Fetch all records with relations from the storage. |
|
| 7 | - * |
|
| 8 | - * @param array $relations |
|
| 9 | - * @param array $sortBy |
|
| 10 | - * @param array $desc |
|
| 11 | - * @param array $columns |
|
| 12 | - * @return collection |
|
| 13 | - */ |
|
| 6 | + * Fetch all records with relations from the storage. |
|
| 7 | + * |
|
| 8 | + * @param array $relations |
|
| 9 | + * @param array $sortBy |
|
| 10 | + * @param array $desc |
|
| 11 | + * @param array $columns |
|
| 12 | + * @return collection |
|
| 13 | + */ |
|
| 14 | 14 | public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Fetch all records with relations from storage in pages |
|
| 18 | - * that matche the given query. |
|
| 19 | - * |
|
| 20 | - * @param string $query |
|
| 21 | - * @param integer $perPage |
|
| 22 | - * @param array $relations |
|
| 23 | - * @param array $sortBy |
|
| 24 | - * @param array $desc |
|
| 25 | - * @param array $columns |
|
| 26 | - * @return collection |
|
| 27 | - */ |
|
| 28 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
| 16 | + /** |
|
| 17 | + * Fetch all records with relations from storage in pages |
|
| 18 | + * that matche the given query. |
|
| 19 | + * |
|
| 20 | + * @param string $query |
|
| 21 | + * @param integer $perPage |
|
| 22 | + * @param array $relations |
|
| 23 | + * @param array $sortBy |
|
| 24 | + * @param array $desc |
|
| 25 | + * @param array $columns |
|
| 26 | + * @return collection |
|
| 27 | + */ |
|
| 28 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * Fetch all records with relations from storage in pages. |
|
| 32 | - * |
|
| 33 | - * @param integer $perPage |
|
| 34 | - * @param array $relations |
|
| 35 | - * @param array $sortBy |
|
| 36 | - * @param array $desc |
|
| 37 | - * @param array $columns |
|
| 38 | - * @return collection |
|
| 39 | - */ |
|
| 40 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
| 31 | + * Fetch all records with relations from storage in pages. |
|
| 32 | + * |
|
| 33 | + * @param integer $perPage |
|
| 34 | + * @param array $relations |
|
| 35 | + * @param array $sortBy |
|
| 36 | + * @param array $desc |
|
| 37 | + * @param array $columns |
|
| 38 | + * @return collection |
|
| 39 | + */ |
|
| 40 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * Fetch all records with relations based on |
|
| 44 | - * the given condition from storage in pages. |
|
| 45 | - * |
|
| 46 | - * @param array $conditions array of conditions |
|
| 47 | - * @param integer $perPage |
|
| 48 | - * @param array $relations |
|
| 49 | - * @param array $sortBy |
|
| 50 | - * @param array $desc |
|
| 51 | - * @param array $columns |
|
| 52 | - * @return collection |
|
| 53 | - */ |
|
| 54 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
| 43 | + * Fetch all records with relations based on |
|
| 44 | + * the given condition from storage in pages. |
|
| 45 | + * |
|
| 46 | + * @param array $conditions array of conditions |
|
| 47 | + * @param integer $perPage |
|
| 48 | + * @param array $relations |
|
| 49 | + * @param array $sortBy |
|
| 50 | + * @param array $desc |
|
| 51 | + * @param array $columns |
|
| 52 | + * @return collection |
|
| 53 | + */ |
|
| 54 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Save the given model/models to the storage. |
|
| 58 | - * |
|
| 59 | - * @param array $data |
|
| 60 | - * @param boolean $saveLog |
|
| 61 | - * @return object |
|
| 62 | - */ |
|
| 63 | - public function save(array $data, $saveLog = true); |
|
| 56 | + /** |
|
| 57 | + * Save the given model/models to the storage. |
|
| 58 | + * |
|
| 59 | + * @param array $data |
|
| 60 | + * @param boolean $saveLog |
|
| 61 | + * @return object |
|
| 62 | + */ |
|
| 63 | + public function save(array $data, $saveLog = true); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Insert multiple records to the storage. |
|
| 67 | - * |
|
| 68 | - * @param array $data |
|
| 69 | - * @return object |
|
| 70 | - */ |
|
| 71 | - public function saveMany(array $data); |
|
| 65 | + /** |
|
| 66 | + * Insert multiple records to the storage. |
|
| 67 | + * |
|
| 68 | + * @param array $data |
|
| 69 | + * @return object |
|
| 70 | + */ |
|
| 71 | + public function saveMany(array $data); |
|
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | - * Update record in the storage based on the given |
|
| 75 | - * condition. |
|
| 76 | - * |
|
| 77 | - * @param [type] $value condition value |
|
| 78 | - * @param array $data |
|
| 79 | - * @param string $attribute condition column name |
|
| 80 | - * @return integer affected rows |
|
| 81 | - */ |
|
| 82 | - public function update($value, array $data, $attribute = 'id'); |
|
| 74 | + * Update record in the storage based on the given |
|
| 75 | + * condition. |
|
| 76 | + * |
|
| 77 | + * @param [type] $value condition value |
|
| 78 | + * @param array $data |
|
| 79 | + * @param string $attribute condition column name |
|
| 80 | + * @return integer affected rows |
|
| 81 | + */ |
|
| 82 | + public function update($value, array $data, $attribute = 'id'); |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | - * Delete record from the storage based on the given |
|
| 86 | - * condition. |
|
| 87 | - * |
|
| 88 | - * @param [type] $value condition value |
|
| 89 | - * @param string $attribute condition column name |
|
| 90 | - * @return integer affected rows |
|
| 91 | - */ |
|
| 92 | - public function delete($value, $attribute = 'id'); |
|
| 85 | + * Delete record from the storage based on the given |
|
| 86 | + * condition. |
|
| 87 | + * |
|
| 88 | + * @param [type] $value condition value |
|
| 89 | + * @param string $attribute condition column name |
|
| 90 | + * @return integer affected rows |
|
| 91 | + */ |
|
| 92 | + public function delete($value, $attribute = 'id'); |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * Fetch records from the storage based on the given |
|
| 96 | - * id. |
|
| 97 | - * |
|
| 98 | - * @param integer $id |
|
| 99 | - * @param array $relations |
|
| 100 | - * @param array $columns |
|
| 101 | - * @return object |
|
| 102 | - */ |
|
| 103 | - public function find($id, $relations = [], $columns = array('*')); |
|
| 95 | + * Fetch records from the storage based on the given |
|
| 96 | + * id. |
|
| 97 | + * |
|
| 98 | + * @param integer $id |
|
| 99 | + * @param array $relations |
|
| 100 | + * @param array $columns |
|
| 101 | + * @return object |
|
| 102 | + */ |
|
| 103 | + public function find($id, $relations = [], $columns = array('*')); |
|
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | - * Fetch records from the storage based on the given |
|
| 107 | - * condition. |
|
| 108 | - * |
|
| 109 | - * @param array $conditions array of conditions |
|
| 110 | - * @param array $relations |
|
| 111 | - * @param array $sortBy |
|
| 112 | - * @param array $desc |
|
| 113 | - * @param array $columns |
|
| 114 | - * @return collection |
|
| 115 | - */ |
|
| 116 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
| 106 | + * Fetch records from the storage based on the given |
|
| 107 | + * condition. |
|
| 108 | + * |
|
| 109 | + * @param array $conditions array of conditions |
|
| 110 | + * @param array $relations |
|
| 111 | + * @param array $sortBy |
|
| 112 | + * @param array $desc |
|
| 113 | + * @param array $columns |
|
| 114 | + * @return collection |
|
| 115 | + */ |
|
| 116 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Fetch the first record fro the storage based on the given |
|
| 120 | - * condition. |
|
| 121 | - * |
|
| 122 | - * @param array $conditions array of conditions |
|
| 123 | - * @param [type] $value condition value |
|
| 124 | - * @param array $relations |
|
| 125 | - * @param array $columns |
|
| 126 | - * @return object |
|
| 127 | - */ |
|
| 128 | - public function first($conditions, $relations = [], $columns = array('*')); |
|
| 118 | + /** |
|
| 119 | + * Fetch the first record fro the storage based on the given |
|
| 120 | + * condition. |
|
| 121 | + * |
|
| 122 | + * @param array $conditions array of conditions |
|
| 123 | + * @param [type] $value condition value |
|
| 124 | + * @param array $relations |
|
| 125 | + * @param array $columns |
|
| 126 | + * @return object |
|
| 127 | + */ |
|
| 128 | + public function first($conditions, $relations = [], $columns = array('*')); |
|
| 129 | 129 | } |
| 130 | 130 | \ No newline at end of file |
@@ -6,30 +6,30 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ApiSkeletonServiceProvider extends ServiceProvider |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Perform post-registration booting of services. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function boot() |
|
| 15 | - { |
|
| 16 | - $this->publishes([ |
|
| 17 | - __DIR__.'/Exceptions' => app_path('Exceptions'), |
|
| 18 | - __DIR__.'/Modules' => app_path('Modules'), |
|
| 19 | - __DIR__.'/notifications' => app_path('notifications'), |
|
| 20 | - __DIR__.'/Kernel.php' => app_path('Http/Kernel.php'), |
|
| 9 | + /** |
|
| 10 | + * Perform post-registration booting of services. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function boot() |
|
| 15 | + { |
|
| 16 | + $this->publishes([ |
|
| 17 | + __DIR__.'/Exceptions' => app_path('Exceptions'), |
|
| 18 | + __DIR__.'/Modules' => app_path('Modules'), |
|
| 19 | + __DIR__.'/notifications' => app_path('notifications'), |
|
| 20 | + __DIR__.'/Kernel.php' => app_path('Http/Kernel.php'), |
|
| 21 | 21 | |
| 22 | - ]); |
|
| 22 | + ]); |
|
| 23 | 23 | |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Register any package services. |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function register() |
|
| 32 | - { |
|
| 33 | - // |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * Register any package services. |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function register() |
|
| 32 | + { |
|
| 33 | + // |
|
| 34 | + } |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -10,56 +10,56 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Handler extends ExceptionHandler |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * A list of the exception types that should not be reported. |
|
| 15 | - * |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - protected $dontReport = [ |
|
| 19 | - HttpException::class, |
|
| 20 | - ModelNotFoundException::class, |
|
| 21 | - ]; |
|
| 13 | + /** |
|
| 14 | + * A list of the exception types that should not be reported. |
|
| 15 | + * |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + protected $dontReport = [ |
|
| 19 | + HttpException::class, |
|
| 20 | + ModelNotFoundException::class, |
|
| 21 | + ]; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Report or log an exception. |
|
| 25 | - * |
|
| 26 | - * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
| 27 | - * |
|
| 28 | - * @param \Exception $e |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function report(Exception $e) |
|
| 32 | - { |
|
| 33 | - return parent::report($e); |
|
| 34 | - } |
|
| 23 | + /** |
|
| 24 | + * Report or log an exception. |
|
| 25 | + * |
|
| 26 | + * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
| 27 | + * |
|
| 28 | + * @param \Exception $e |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function report(Exception $e) |
|
| 32 | + { |
|
| 33 | + return parent::report($e); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Render an exception into an HTTP response. |
|
| 38 | - * |
|
| 39 | - * @param \Illuminate\Http\Request $request |
|
| 40 | - * @param \Exception $e |
|
| 41 | - * @return \Illuminate\Http\Response |
|
| 42 | - */ |
|
| 43 | - public function render($request, Exception $e) |
|
| 44 | - { |
|
| 45 | - if ($e instanceof ModelNotFoundException) { |
|
| 46 | - $e = new NotFoundHttpException($e->getMessage(), $e); |
|
| 47 | - } |
|
| 36 | + /** |
|
| 37 | + * Render an exception into an HTTP response. |
|
| 38 | + * |
|
| 39 | + * @param \Illuminate\Http\Request $request |
|
| 40 | + * @param \Exception $e |
|
| 41 | + * @return \Illuminate\Http\Response |
|
| 42 | + */ |
|
| 43 | + public function render($request, Exception $e) |
|
| 44 | + { |
|
| 45 | + if ($e instanceof ModelNotFoundException) { |
|
| 46 | + $e = new NotFoundHttpException($e->getMessage(), $e); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - if ($request->wantsJson()) |
|
| 50 | - { |
|
| 51 | - if ($e instanceof \Illuminate\Database\QueryException) |
|
| 52 | - { |
|
| 53 | - return \Response::json('Please check the given inputes', '400'); |
|
| 54 | - } |
|
| 55 | - else if ($e instanceof \predis\connection\connectionexception) |
|
| 56 | - { |
|
| 57 | - return \Response::json('Your redis notification server isn\'t running', '400'); |
|
| 58 | - } |
|
| 49 | + if ($request->wantsJson()) |
|
| 50 | + { |
|
| 51 | + if ($e instanceof \Illuminate\Database\QueryException) |
|
| 52 | + { |
|
| 53 | + return \Response::json('Please check the given inputes', '400'); |
|
| 54 | + } |
|
| 55 | + else if ($e instanceof \predis\connection\connectionexception) |
|
| 56 | + { |
|
| 57 | + return \Response::json('Your redis notification server isn\'t running', '400'); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return \Response::json($e->getMessage(), $e->getStatusCode()); |
|
| 61 | - } |
|
| 60 | + return \Response::json($e->getMessage(), $e->getStatusCode()); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return parent::render($request, $e); |
|
| 64 | - } |
|
| 63 | + return parent::render($request, $e); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -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 | } |
@@ -5,47 +5,47 @@ |
||
| 5 | 5 | |
| 6 | 6 | class AclGroup extends Model{ |
| 7 | 7 | |
| 8 | - use SoftDeletes; |
|
| 9 | - protected $table = 'groups'; |
|
| 10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | - protected $hidden = ['deleted_at']; |
|
| 12 | - protected $guarded = ['id']; |
|
| 13 | - protected $fillable = ['name']; |
|
| 14 | - |
|
| 15 | - public function getCreatedAtAttribute($value) |
|
| 16 | - { |
|
| 17 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - public function getUpdatedAtAttribute($value) |
|
| 21 | - { |
|
| 22 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function getDeletedAtAttribute($value) |
|
| 26 | - { |
|
| 27 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function users() |
|
| 31 | - { |
|
| 32 | - return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function permissions() |
|
| 36 | - { |
|
| 37 | - return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public static function boot() |
|
| 41 | - { |
|
| 42 | - parent::boot(); |
|
| 43 | - |
|
| 44 | - AclGroup::deleting(function($group) |
|
| 45 | - { |
|
| 46 | - \DB::table('groups_permissions') |
|
| 47 | - ->where('group_id', $group->id) |
|
| 48 | - ->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 49 | - }); |
|
| 50 | - } |
|
| 8 | + use SoftDeletes; |
|
| 9 | + protected $table = 'groups'; |
|
| 10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | + protected $hidden = ['deleted_at']; |
|
| 12 | + protected $guarded = ['id']; |
|
| 13 | + protected $fillable = ['name']; |
|
| 14 | + |
|
| 15 | + public function getCreatedAtAttribute($value) |
|
| 16 | + { |
|
| 17 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + public function getUpdatedAtAttribute($value) |
|
| 21 | + { |
|
| 22 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function getDeletedAtAttribute($value) |
|
| 26 | + { |
|
| 27 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function users() |
|
| 31 | + { |
|
| 32 | + return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function permissions() |
|
| 36 | + { |
|
| 37 | + return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public static function boot() |
|
| 41 | + { |
|
| 42 | + parent::boot(); |
|
| 43 | + |
|
| 44 | + AclGroup::deleting(function($group) |
|
| 45 | + { |
|
| 46 | + \DB::table('groups_permissions') |
|
| 47 | + ->where('group_id', $group->id) |
|
| 48 | + ->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 49 | + }); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -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() |
@@ -61,6 +61,6 @@ |
||
| 61 | 61 | $user->groups()->attach($group_ids); |
| 62 | 62 | }); |
| 63 | 63 | |
| 64 | - return \Core::users()->find($user_id); |
|
| 64 | + return \Core::users()->find($user_id); |
|
| 65 | 65 | } |
| 66 | 66 | } |
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | * @param boolean $user |
| 24 | 24 | * @return boolean |
| 25 | 25 | */ |
| 26 | - public function can($nameOfPermission, $model, $user = false ) |
|
| 26 | + public function can($nameOfPermission, $model, $user = false) |
|
| 27 | 27 | { |
| 28 | 28 | $user = $user ?: \Auth::user(); |
| 29 | 29 | $permissions = []; |
| 30 | - \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
| 30 | + \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function($permission) use (&$permissions, $model){ |
|
| 31 | 31 | $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); |
| 32 | 32 | }); |
| 33 | 33 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function assignGroups($user_id, $group_ids) |
| 57 | 57 | { |
| 58 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 58 | + \DB::transaction(function() use ($user_id, $group_ids) { |
|
| 59 | 59 | $user = \Core::users()->find($user_id); |
| 60 | 60 | $user->groups()->detach(); |
| 61 | 61 | $user->groups()->attach($group_ids); |
@@ -29,6 +29,6 @@ |
||
| 29 | 29 | $group->permissions()->attach($permission_ids); |
| 30 | 30 | }); |
| 31 | 31 | |
| 32 | - return \Core::groups()->find($group_id); |
|
| 32 | + return \Core::groups()->find($group_id); |
|
| 33 | 33 | } |
| 34 | 34 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | public function assignPermissions($group_id, $permission_ids) |
| 25 | 25 | { |
| 26 | - \DB::transaction(function () use ($group_id, $permission_ids) { |
|
| 26 | + \DB::transaction(function() use ($group_id, $permission_ids) { |
|
| 27 | 27 | $group = \Core::groups()->find($group_id); |
| 28 | 28 | $group->permissions()->detach(); |
| 29 | 29 | $group->permissions()->attach($permission_ids); |
@@ -8,35 +8,35 @@ |
||
| 8 | 8 | |
| 9 | 9 | class GroupsController extends BaseApiController |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The name of the model that is used by the base api controller |
|
| 13 | - * to preform actions like (add, edit ... etc). |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $model = 'groups'; |
|
| 11 | + /** |
|
| 12 | + * The name of the model that is used by the base api controller |
|
| 13 | + * to preform actions like (add, edit ... etc). |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $model = 'groups'; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The validations rules used by the base api controller |
|
| 20 | - * to check before add. |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $validationRules = [ |
|
| 24 | - 'name' => 'required|string|max:100|unique:groups,name,{id}' |
|
| 25 | - ]; |
|
| 18 | + /** |
|
| 19 | + * The validations rules used by the base api controller |
|
| 20 | + * to check before add. |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $validationRules = [ |
|
| 24 | + 'name' => 'required|string|max:100|unique:groups,name,{id}' |
|
| 25 | + ]; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Handle an assign permissions to group request. |
|
| 29 | - * |
|
| 30 | - * @param \Illuminate\Http\Request $request |
|
| 31 | - * @return \Illuminate\Http\Response |
|
| 32 | - */ |
|
| 33 | - public function postAssignpermissions(Request $request) |
|
| 34 | - { |
|
| 35 | - $this->validate($request, [ |
|
| 36 | - 'permission_ids' => 'required|exists:permissions,id', |
|
| 37 | - 'group_id' => 'required|exists:groups,id' |
|
| 38 | - ]); |
|
| 27 | + /** |
|
| 28 | + * Handle an assign permissions to group request. |
|
| 29 | + * |
|
| 30 | + * @param \Illuminate\Http\Request $request |
|
| 31 | + * @return \Illuminate\Http\Response |
|
| 32 | + */ |
|
| 33 | + public function postAssignpermissions(Request $request) |
|
| 34 | + { |
|
| 35 | + $this->validate($request, [ |
|
| 36 | + 'permission_ids' => 'required|exists:permissions,id', |
|
| 37 | + 'group_id' => 'required|exists:groups,id' |
|
| 38 | + ]); |
|
| 39 | 39 | |
| 40 | - return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200); |
|
| 41 | - } |
|
| 40 | + return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | * to preform actions like (add, edit ... etc). |
| 14 | 14 | * @var string |
| 15 | 15 | */ |
| 16 | - protected $model = 'groups'; |
|
| 16 | + protected $model = 'groups'; |
|
| 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|unique:groups,name,{id}' |
| 25 | 25 | ]; |
| 26 | 26 | |