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