@@ -29,6 +29,6 @@ |
||
29 | 29 | $group->permissions()->attach($permission_ids); |
30 | 30 | }); |
31 | 31 | |
32 | - return $this->find($group_id); |
|
32 | + return $this->find($group_id); |
|
33 | 33 | } |
34 | 34 | } |
@@ -2,119 +2,119 @@ |
||
2 | 2 | |
3 | 3 | interface RepositoryInterface |
4 | 4 | { |
5 | - /** |
|
6 | - * Fetch all records with relations from the storage. |
|
7 | - * |
|
8 | - * @param array $relations |
|
9 | - * @param array $sortBy |
|
10 | - * @param array $desc |
|
11 | - * @param array $columns |
|
12 | - * @return collection |
|
13 | - */ |
|
14 | - public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
5 | + /** |
|
6 | + * Fetch all records with relations from the storage. |
|
7 | + * |
|
8 | + * @param array $relations |
|
9 | + * @param array $sortBy |
|
10 | + * @param array $desc |
|
11 | + * @param array $columns |
|
12 | + * @return collection |
|
13 | + */ |
|
14 | + public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
15 | 15 | |
16 | - /** |
|
17 | - * Fetch all records with relations from storage in pages |
|
18 | - * that matche the given query. |
|
19 | - * |
|
20 | - * @param string $query |
|
21 | - * @param integer $perPage |
|
22 | - * @param array $relations |
|
23 | - * @param array $sortBy |
|
24 | - * @param array $desc |
|
25 | - * @param array $columns |
|
26 | - * @return collection |
|
27 | - */ |
|
28 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
16 | + /** |
|
17 | + * Fetch all records with relations from storage in pages |
|
18 | + * that matche the given query. |
|
19 | + * |
|
20 | + * @param string $query |
|
21 | + * @param integer $perPage |
|
22 | + * @param array $relations |
|
23 | + * @param array $sortBy |
|
24 | + * @param array $desc |
|
25 | + * @param array $columns |
|
26 | + * @return collection |
|
27 | + */ |
|
28 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
29 | 29 | |
30 | - /** |
|
31 | - * Fetch all records with relations from storage in pages. |
|
32 | - * |
|
33 | - * @param integer $perPage |
|
34 | - * @param array $relations |
|
35 | - * @param array $sortBy |
|
36 | - * @param array $desc |
|
37 | - * @param array $columns |
|
38 | - * @return collection |
|
39 | - */ |
|
40 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
30 | + /** |
|
31 | + * Fetch all records with relations from storage in pages. |
|
32 | + * |
|
33 | + * @param integer $perPage |
|
34 | + * @param array $relations |
|
35 | + * @param array $sortBy |
|
36 | + * @param array $desc |
|
37 | + * @param array $columns |
|
38 | + * @return collection |
|
39 | + */ |
|
40 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Fetch all records with relations based on |
|
44 | - * the given condition from storage in pages. |
|
45 | - * |
|
46 | - * @param array $conditions array of conditions |
|
47 | - * @param integer $perPage |
|
48 | - * @param array $relations |
|
49 | - * @param array $sortBy |
|
50 | - * @param array $desc |
|
51 | - * @param array $columns |
|
52 | - * @return collection |
|
53 | - */ |
|
54 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
42 | + /** |
|
43 | + * Fetch all records with relations based on |
|
44 | + * the given condition from storage in pages. |
|
45 | + * |
|
46 | + * @param array $conditions array of conditions |
|
47 | + * @param integer $perPage |
|
48 | + * @param array $relations |
|
49 | + * @param array $sortBy |
|
50 | + * @param array $desc |
|
51 | + * @param array $columns |
|
52 | + * @return collection |
|
53 | + */ |
|
54 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Save the given model/models to the storage. |
|
58 | - * |
|
59 | - * @param array $data |
|
60 | - * @param boolean $saveLog |
|
61 | - * @return object |
|
62 | - */ |
|
63 | - public function save(array $data, $saveLog = true); |
|
56 | + /** |
|
57 | + * Save the given model/models to the storage. |
|
58 | + * |
|
59 | + * @param array $data |
|
60 | + * @param boolean $saveLog |
|
61 | + * @return object |
|
62 | + */ |
|
63 | + public function save(array $data, $saveLog = true); |
|
64 | 64 | |
65 | - /** |
|
66 | - * Update record in the storage based on the given |
|
67 | - * condition. |
|
68 | - * |
|
69 | - * @param var $value condition value |
|
70 | - * @param array $data |
|
71 | - * @param string $attribute condition column name |
|
72 | - * @return integer affected rows |
|
73 | - */ |
|
74 | - public function update($value, array $data, $attribute = 'id'); |
|
65 | + /** |
|
66 | + * Update record in the storage based on the given |
|
67 | + * condition. |
|
68 | + * |
|
69 | + * @param var $value condition value |
|
70 | + * @param array $data |
|
71 | + * @param string $attribute condition column name |
|
72 | + * @return integer affected rows |
|
73 | + */ |
|
74 | + public function update($value, array $data, $attribute = 'id'); |
|
75 | 75 | |
76 | - /** |
|
77 | - * Delete record from the storage based on the given |
|
78 | - * condition. |
|
79 | - * |
|
80 | - * @param var $value condition value |
|
81 | - * @param string $attribute condition column name |
|
82 | - * @return integer affected rows |
|
83 | - */ |
|
84 | - public function delete($value, $attribute = 'id'); |
|
76 | + /** |
|
77 | + * Delete record from the storage based on the given |
|
78 | + * condition. |
|
79 | + * |
|
80 | + * @param var $value condition value |
|
81 | + * @param string $attribute condition column name |
|
82 | + * @return integer affected rows |
|
83 | + */ |
|
84 | + public function delete($value, $attribute = 'id'); |
|
85 | 85 | |
86 | - /** |
|
87 | - * Fetch records from the storage based on the given |
|
88 | - * id. |
|
89 | - * |
|
90 | - * @param integer $id |
|
91 | - * @param array $relations |
|
92 | - * @param array $columns |
|
93 | - * @return object |
|
94 | - */ |
|
95 | - public function find($id, $relations = [], $columns = array('*')); |
|
86 | + /** |
|
87 | + * Fetch records from the storage based on the given |
|
88 | + * id. |
|
89 | + * |
|
90 | + * @param integer $id |
|
91 | + * @param array $relations |
|
92 | + * @param array $columns |
|
93 | + * @return object |
|
94 | + */ |
|
95 | + public function find($id, $relations = [], $columns = array('*')); |
|
96 | 96 | |
97 | - /** |
|
98 | - * Fetch records from the storage based on the given |
|
99 | - * condition. |
|
100 | - * |
|
101 | - * @param array $conditions array of conditions |
|
102 | - * @param array $relations |
|
103 | - * @param array $sortBy |
|
104 | - * @param array $desc |
|
105 | - * @param array $columns |
|
106 | - * @return collection |
|
107 | - */ |
|
108 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
97 | + /** |
|
98 | + * Fetch records from the storage based on the given |
|
99 | + * condition. |
|
100 | + * |
|
101 | + * @param array $conditions array of conditions |
|
102 | + * @param array $relations |
|
103 | + * @param array $sortBy |
|
104 | + * @param array $desc |
|
105 | + * @param array $columns |
|
106 | + * @return collection |
|
107 | + */ |
|
108 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
109 | 109 | |
110 | - /** |
|
111 | - * Fetch the first record fro the storage based on the given |
|
112 | - * condition. |
|
113 | - * |
|
114 | - * @param array $conditions array of conditions |
|
115 | - * @param array $relations |
|
116 | - * @param array $columns |
|
117 | - * @return object |
|
118 | - */ |
|
119 | - public function first($conditions, $relations = [], $columns = array('*')); |
|
110 | + /** |
|
111 | + * Fetch the first record fro the storage based on the given |
|
112 | + * condition. |
|
113 | + * |
|
114 | + * @param array $conditions array of conditions |
|
115 | + * @param array $relations |
|
116 | + * @param array $columns |
|
117 | + * @return object |
|
118 | + */ |
|
119 | + public function first($conditions, $relations = [], $columns = array('*')); |
|
120 | 120 | } |
121 | 121 | \ No newline at end of file |
@@ -15,23 +15,23 @@ |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | - * Set the notification notified to true. |
|
19 | - * |
|
20 | - * @param integer $id |
|
21 | - * @return object |
|
22 | - */ |
|
23 | - public function notified($id) |
|
24 | - { |
|
25 | - return $this->save(['id' => $id, 'notified' => 1]); |
|
26 | - } |
|
18 | + * Set the notification notified to true. |
|
19 | + * |
|
20 | + * @param integer $id |
|
21 | + * @return object |
|
22 | + */ |
|
23 | + public function notified($id) |
|
24 | + { |
|
25 | + return $this->save(['id' => $id, 'notified' => 1]); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Set the notification notified to all. |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function notifyAll() |
|
34 | - { |
|
35 | - $this->update(false, ['notified' => 1], 'notified'); |
|
36 | - } |
|
28 | + /** |
|
29 | + * Set the notification notified to all. |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function notifyAll() |
|
34 | + { |
|
35 | + $this->update(false, ['notified' => 1], 'notified'); |
|
36 | + } |
|
37 | 37 | } |
@@ -7,184 +7,184 @@ |
||
7 | 7 | |
8 | 8 | class UsersController extends BaseApiController |
9 | 9 | { |
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 = 'users'; |
|
16 | - |
|
17 | - /** |
|
18 | - * List of all route actions that the base api controller |
|
19 | - * will skip permissions check for them. |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $skipPermissionCheck = ['account', 'logout', 'sendreset']; |
|
23 | - |
|
24 | - /** |
|
25 | - * List of all route actions that the base api controller |
|
26 | - * will skip login check for them. |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
30 | - |
|
31 | - /** |
|
32 | - * The validations rules used by the base api controller |
|
33 | - * to check before add. |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $validationRules = [ |
|
37 | - 'email' => 'required|email|unique:users,email,{id}', |
|
38 | - 'password' => 'min:6' |
|
39 | - ]; |
|
40 | - |
|
41 | - /** |
|
42 | - * Return the logged in user account. |
|
43 | - * |
|
44 | - * @return \Illuminate\Http\Response |
|
45 | - */ |
|
46 | - public function account() |
|
47 | - { |
|
48 | - $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
49 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Block the user. |
|
54 | - * |
|
55 | - * @param integer $id |
|
56 | - * @return \Illuminate\Http\Response |
|
57 | - */ |
|
58 | - public function block($id) |
|
59 | - { |
|
60 | - return \Response::json(\Core::users()->block($id), 200); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Unblock the user. |
|
65 | - * |
|
66 | - * @param integer $id |
|
67 | - * @return \Illuminate\Http\Response |
|
68 | - */ |
|
69 | - public function unblock($id) |
|
70 | - { |
|
71 | - return \Response::json(\Core::users()->unblock($id), 200); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Logout the user. |
|
76 | - * |
|
77 | - * @return \Illuminate\Http\Response |
|
78 | - */ |
|
79 | - public function logout() |
|
80 | - { |
|
81 | - return \Response::json(\Core::users()->logout(), 200); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Handle a registration request. |
|
86 | - * |
|
87 | - * @param \Illuminate\Http\Request $request |
|
88 | - * @return \Illuminate\Http\Response |
|
89 | - */ |
|
90 | - public function register(Request $request) |
|
91 | - { |
|
92 | - $this->validate($request, [ |
|
93 | - 'email' => 'required|email|unique:users,email,{id}', |
|
94 | - 'password' => 'required|min:6' |
|
95 | - ]); |
|
96 | - |
|
97 | - return \Response::json(\Core::users()->register($request->only('email', 'password')), 200); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Handle a login request of the none admin to the application. |
|
102 | - * |
|
103 | - * @param \Illuminate\Http\Request $request |
|
104 | - * @return \Illuminate\Http\Response |
|
105 | - */ |
|
106 | - public function login(Request $request) |
|
107 | - { |
|
108 | - $this->validate($request, [ |
|
109 | - 'email' => 'required|email', |
|
110 | - 'password' => 'required|min:6', |
|
111 | - 'admin' => 'boolean' |
|
112 | - ]); |
|
113 | - |
|
114 | - return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Handle a social login request of the none admin to the application. |
|
119 | - * |
|
120 | - * @param \Illuminate\Http\Request $request |
|
121 | - * @return \Illuminate\Http\Response |
|
122 | - */ |
|
123 | - public function loginSocial(Request $request) |
|
124 | - { |
|
125 | - $this->validate($request, [ |
|
126 | - 'auth_code' => 'required_without:access_token', |
|
127 | - 'access_token' => 'required_without:auth_code', |
|
128 | - 'type' => 'required|in:facebook,google' |
|
129 | - ]); |
|
130 | - |
|
131 | - return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Handle an assign groups to user request. |
|
136 | - * |
|
137 | - * @param \Illuminate\Http\Request $request |
|
138 | - * @return \Illuminate\Http\Response |
|
139 | - */ |
|
140 | - public function assigngroups(Request $request) |
|
141 | - { |
|
142 | - $this->validate($request, [ |
|
143 | - 'group_ids' => 'required|exists:groups,id', |
|
144 | - 'user_id' => 'required|exists:users,id' |
|
145 | - ]); |
|
146 | - |
|
147 | - return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Send a reset link to the given user. |
|
152 | - * |
|
153 | - * @param \Illuminate\Http\Request $request |
|
154 | - * @return \Illuminate\Http\Response |
|
155 | - */ |
|
156 | - public function sendreset(Request $request) |
|
157 | - { |
|
158 | - $this->validate($request, ['email' => 'required|email', 'url' => 'required|url']); |
|
159 | - |
|
160 | - return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Reset the given user's password. |
|
165 | - * |
|
166 | - * @param \Illuminate\Http\Request $request |
|
167 | - * @return \Illuminate\Http\Response |
|
168 | - */ |
|
169 | - public function resetpassword(Request $request) |
|
170 | - { |
|
171 | - $this->validate($request, [ |
|
172 | - 'token' => 'required', |
|
173 | - 'email' => 'required|email', |
|
174 | - 'password' => 'required|confirmed|min:6', |
|
175 | - 'password_confirmation' => 'required', |
|
176 | - ]); |
|
177 | - |
|
178 | - return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Refresh the expired login token. |
|
183 | - * |
|
184 | - * @return \Illuminate\Http\Response |
|
185 | - */ |
|
186 | - public function refreshtoken() |
|
187 | - { |
|
188 | - return \Response::json(\Core::users()->refreshtoken(), 200); |
|
189 | - } |
|
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 = 'users'; |
|
16 | + |
|
17 | + /** |
|
18 | + * List of all route actions that the base api controller |
|
19 | + * will skip permissions check for them. |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $skipPermissionCheck = ['account', 'logout', 'sendreset']; |
|
23 | + |
|
24 | + /** |
|
25 | + * List of all route actions that the base api controller |
|
26 | + * will skip login check for them. |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
30 | + |
|
31 | + /** |
|
32 | + * The validations rules used by the base api controller |
|
33 | + * to check before add. |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $validationRules = [ |
|
37 | + 'email' => 'required|email|unique:users,email,{id}', |
|
38 | + 'password' => 'min:6' |
|
39 | + ]; |
|
40 | + |
|
41 | + /** |
|
42 | + * Return the logged in user account. |
|
43 | + * |
|
44 | + * @return \Illuminate\Http\Response |
|
45 | + */ |
|
46 | + public function account() |
|
47 | + { |
|
48 | + $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
49 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Block the user. |
|
54 | + * |
|
55 | + * @param integer $id |
|
56 | + * @return \Illuminate\Http\Response |
|
57 | + */ |
|
58 | + public function block($id) |
|
59 | + { |
|
60 | + return \Response::json(\Core::users()->block($id), 200); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Unblock the user. |
|
65 | + * |
|
66 | + * @param integer $id |
|
67 | + * @return \Illuminate\Http\Response |
|
68 | + */ |
|
69 | + public function unblock($id) |
|
70 | + { |
|
71 | + return \Response::json(\Core::users()->unblock($id), 200); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Logout the user. |
|
76 | + * |
|
77 | + * @return \Illuminate\Http\Response |
|
78 | + */ |
|
79 | + public function logout() |
|
80 | + { |
|
81 | + return \Response::json(\Core::users()->logout(), 200); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Handle a registration request. |
|
86 | + * |
|
87 | + * @param \Illuminate\Http\Request $request |
|
88 | + * @return \Illuminate\Http\Response |
|
89 | + */ |
|
90 | + public function register(Request $request) |
|
91 | + { |
|
92 | + $this->validate($request, [ |
|
93 | + 'email' => 'required|email|unique:users,email,{id}', |
|
94 | + 'password' => 'required|min:6' |
|
95 | + ]); |
|
96 | + |
|
97 | + return \Response::json(\Core::users()->register($request->only('email', 'password')), 200); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Handle a login request of the none admin to the application. |
|
102 | + * |
|
103 | + * @param \Illuminate\Http\Request $request |
|
104 | + * @return \Illuminate\Http\Response |
|
105 | + */ |
|
106 | + public function login(Request $request) |
|
107 | + { |
|
108 | + $this->validate($request, [ |
|
109 | + 'email' => 'required|email', |
|
110 | + 'password' => 'required|min:6', |
|
111 | + 'admin' => 'boolean' |
|
112 | + ]); |
|
113 | + |
|
114 | + return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Handle a social login request of the none admin to the application. |
|
119 | + * |
|
120 | + * @param \Illuminate\Http\Request $request |
|
121 | + * @return \Illuminate\Http\Response |
|
122 | + */ |
|
123 | + public function loginSocial(Request $request) |
|
124 | + { |
|
125 | + $this->validate($request, [ |
|
126 | + 'auth_code' => 'required_without:access_token', |
|
127 | + 'access_token' => 'required_without:auth_code', |
|
128 | + 'type' => 'required|in:facebook,google' |
|
129 | + ]); |
|
130 | + |
|
131 | + return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Handle an assign groups to user request. |
|
136 | + * |
|
137 | + * @param \Illuminate\Http\Request $request |
|
138 | + * @return \Illuminate\Http\Response |
|
139 | + */ |
|
140 | + public function assigngroups(Request $request) |
|
141 | + { |
|
142 | + $this->validate($request, [ |
|
143 | + 'group_ids' => 'required|exists:groups,id', |
|
144 | + 'user_id' => 'required|exists:users,id' |
|
145 | + ]); |
|
146 | + |
|
147 | + return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Send a reset link to the given user. |
|
152 | + * |
|
153 | + * @param \Illuminate\Http\Request $request |
|
154 | + * @return \Illuminate\Http\Response |
|
155 | + */ |
|
156 | + public function sendreset(Request $request) |
|
157 | + { |
|
158 | + $this->validate($request, ['email' => 'required|email', 'url' => 'required|url']); |
|
159 | + |
|
160 | + return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Reset the given user's password. |
|
165 | + * |
|
166 | + * @param \Illuminate\Http\Request $request |
|
167 | + * @return \Illuminate\Http\Response |
|
168 | + */ |
|
169 | + public function resetpassword(Request $request) |
|
170 | + { |
|
171 | + $this->validate($request, [ |
|
172 | + 'token' => 'required', |
|
173 | + 'email' => 'required|email', |
|
174 | + 'password' => 'required|confirmed|min:6', |
|
175 | + 'password_confirmation' => 'required', |
|
176 | + ]); |
|
177 | + |
|
178 | + return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Refresh the expired login token. |
|
183 | + * |
|
184 | + * @return \Illuminate\Http\Response |
|
185 | + */ |
|
186 | + public function refreshtoken() |
|
187 | + { |
|
188 | + return \Response::json(\Core::users()->refreshtoken(), 200); |
|
189 | + } |
|
190 | 190 | } |
@@ -4,66 +4,66 @@ |
||
4 | 4 | |
5 | 5 | class ReportRepository extends AbstractRepository |
6 | 6 | { |
7 | - /** |
|
8 | - * Return the model full namespace. |
|
9 | - * |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - protected function getModel() |
|
13 | - { |
|
14 | - return 'App\Modules\V1\Reporting\Report'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * Return the model full namespace. |
|
9 | + * |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + protected function getModel() |
|
13 | + { |
|
14 | + return 'App\Modules\V1\Reporting\Report'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * Render the given report db view based on the given |
|
19 | - * condition. |
|
20 | - * |
|
21 | - * @param string $reportName |
|
22 | - * @param array $conditions array of conditions |
|
23 | - * @param integer $perPage |
|
24 | - * @param array $relations |
|
25 | - * @return object |
|
26 | - */ |
|
27 | - public function getReport($reportName, $conditions = false, $perPage = 0, $relations = []) |
|
28 | - { |
|
29 | - /** |
|
30 | - * Fetch the report from db. |
|
31 | - */ |
|
32 | - $reportConditions = $this->constructConditions(['report_name' => $reportName]); |
|
33 | - $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($reportConditions['conditionString'], $reportConditions['conditionValues'])->first(); |
|
17 | + /** |
|
18 | + * Render the given report db view based on the given |
|
19 | + * condition. |
|
20 | + * |
|
21 | + * @param string $reportName |
|
22 | + * @param array $conditions array of conditions |
|
23 | + * @param integer $perPage |
|
24 | + * @param array $relations |
|
25 | + * @return object |
|
26 | + */ |
|
27 | + public function getReport($reportName, $conditions = false, $perPage = 0, $relations = []) |
|
28 | + { |
|
29 | + /** |
|
30 | + * Fetch the report from db. |
|
31 | + */ |
|
32 | + $reportConditions = $this->constructConditions(['report_name' => $reportName]); |
|
33 | + $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($reportConditions['conditionString'], $reportConditions['conditionValues'])->first(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Check report existance and permission. |
|
37 | - */ |
|
38 | - if ( ! $report) |
|
39 | - { |
|
40 | - \ErrorHandler::notFound('report'); |
|
41 | - } |
|
42 | - else if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
43 | - { |
|
44 | - \ErrorHandler::noPermissions(); |
|
45 | - } |
|
35 | + /** |
|
36 | + * Check report existance and permission. |
|
37 | + */ |
|
38 | + if ( ! $report) |
|
39 | + { |
|
40 | + \ErrorHandler::notFound('report'); |
|
41 | + } |
|
42 | + else if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
43 | + { |
|
44 | + \ErrorHandler::noPermissions(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Fetch data from the report based on the given conditions. |
|
49 | - */ |
|
50 | - $report = \DB::table($report->view_name); |
|
51 | - unset($conditions['page']); |
|
52 | - if (count($conditions)) |
|
53 | - { |
|
54 | - $conditions = $this->constructConditions($conditions); |
|
55 | - $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
56 | - } |
|
57 | - /** |
|
58 | - * Paginate or all data. |
|
59 | - */ |
|
60 | - if ($perPage) |
|
61 | - { |
|
62 | - return $report->paginate($perPage); |
|
63 | - } |
|
64 | - else |
|
65 | - { |
|
66 | - return $report->get(); |
|
67 | - } |
|
68 | - } |
|
47 | + /** |
|
48 | + * Fetch data from the report based on the given conditions. |
|
49 | + */ |
|
50 | + $report = \DB::table($report->view_name); |
|
51 | + unset($conditions['page']); |
|
52 | + if (count($conditions)) |
|
53 | + { |
|
54 | + $conditions = $this->constructConditions($conditions); |
|
55 | + $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
56 | + } |
|
57 | + /** |
|
58 | + * Paginate or all data. |
|
59 | + */ |
|
60 | + if ($perPage) |
|
61 | + { |
|
62 | + return $report->paginate($perPage); |
|
63 | + } |
|
64 | + else |
|
65 | + { |
|
66 | + return $report->get(); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
@@ -7,33 +7,33 @@ |
||
7 | 7 | |
8 | 8 | class ReportsController extends BaseApiController |
9 | 9 | { |
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 = 'reports'; |
|
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 = 'reports'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * List of all route actions that the base api controller |
|
19 | - * will skip permissions check for them. |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $skipPermissionCheck = ['getReport']; |
|
17 | + /** |
|
18 | + * List of all route actions that the base api controller |
|
19 | + * will skip permissions check for them. |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $skipPermissionCheck = ['getReport']; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Render the total income report db view between the given two dates. |
|
26 | - * |
|
27 | - * @param \Illuminate\Http\Request $request |
|
28 | - * @param string $reportName |
|
29 | - * @param integer $perPage |
|
30 | - * @return \Illuminate\Http\Response |
|
31 | - */ |
|
32 | - public function getReport(Request $request, $reportName, $perPage = 0) |
|
33 | - { |
|
34 | - if ($this->model) |
|
35 | - { |
|
36 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->getReport($reportName, $request->all(), $perPage), 200); |
|
37 | - } |
|
38 | - } |
|
24 | + /** |
|
25 | + * Render the total income report db view between the given two dates. |
|
26 | + * |
|
27 | + * @param \Illuminate\Http\Request $request |
|
28 | + * @param string $reportName |
|
29 | + * @param integer $perPage |
|
30 | + * @return \Illuminate\Http\Response |
|
31 | + */ |
|
32 | + public function getReport(Request $request, $reportName, $perPage = 0) |
|
33 | + { |
|
34 | + if ($this->model) |
|
35 | + { |
|
36 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->getReport($reportName, $request->all(), $perPage), 200); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | } |
@@ -6,67 +6,67 @@ |
||
6 | 6 | |
7 | 7 | class AclUser extends User { |
8 | 8 | |
9 | - use SoftDeletes; |
|
10 | - protected $table = 'users'; |
|
11 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
12 | - protected $hidden = ['password', 'remember_token','deleted_at']; |
|
13 | - protected $guarded = ['id']; |
|
14 | - protected $fillable = ['name', 'email', 'password']; |
|
15 | - protected $appends = ['permissions']; |
|
16 | - public $searchable = ['name', 'email']; |
|
9 | + use SoftDeletes; |
|
10 | + protected $table = 'users'; |
|
11 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
12 | + protected $hidden = ['password', 'remember_token','deleted_at']; |
|
13 | + protected $guarded = ['id']; |
|
14 | + protected $fillable = ['name', 'email', 'password']; |
|
15 | + protected $appends = ['permissions']; |
|
16 | + public $searchable = ['name', 'email']; |
|
17 | 17 | |
18 | - public function getCreatedAtAttribute($value) |
|
19 | - { |
|
20 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21 | - } |
|
18 | + public function getCreatedAtAttribute($value) |
|
19 | + { |
|
20 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21 | + } |
|
22 | 22 | |
23 | - public function getUpdatedAtAttribute($value) |
|
24 | - { |
|
25 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
26 | - } |
|
23 | + public function getUpdatedAtAttribute($value) |
|
24 | + { |
|
25 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
26 | + } |
|
27 | 27 | |
28 | - public function getDeletedAtAttribute($value) |
|
29 | - { |
|
30 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
31 | - } |
|
28 | + public function getDeletedAtAttribute($value) |
|
29 | + { |
|
30 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Encrypt the password attribute before |
|
35 | - * saving it in the storage. |
|
36 | - * |
|
37 | - * @param string $value |
|
38 | - */ |
|
39 | - public function setPasswordAttribute($value) |
|
40 | - { |
|
41 | - $this->attributes['password'] = bcrypt($value); |
|
42 | - } |
|
33 | + /** |
|
34 | + * Encrypt the password attribute before |
|
35 | + * saving it in the storage. |
|
36 | + * |
|
37 | + * @param string $value |
|
38 | + */ |
|
39 | + public function setPasswordAttribute($value) |
|
40 | + { |
|
41 | + $this->attributes['password'] = bcrypt($value); |
|
42 | + } |
|
43 | 43 | |
44 | - public function logs() |
|
45 | - { |
|
46 | - return $this->hasMany('App\Modules\V1\Core\Log', 'user_id'); |
|
47 | - } |
|
44 | + public function logs() |
|
45 | + { |
|
46 | + return $this->hasMany('App\Modules\V1\Core\Log', 'user_id'); |
|
47 | + } |
|
48 | 48 | |
49 | - public function groups() |
|
50 | - { |
|
51 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
52 | - } |
|
49 | + public function groups() |
|
50 | + { |
|
51 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
52 | + } |
|
53 | 53 | |
54 | - public function getPermissionsAttribute() |
|
55 | - { |
|
56 | - $permissions = []; |
|
57 | - foreach ($this->groups()->get() as $group) |
|
58 | - { |
|
59 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
60 | - $permissions[$permission->model][$permission->id] = $permission->name; |
|
61 | - }); |
|
62 | - } |
|
54 | + public function getPermissionsAttribute() |
|
55 | + { |
|
56 | + $permissions = []; |
|
57 | + foreach ($this->groups()->get() as $group) |
|
58 | + { |
|
59 | + $group->permissions->each(function ($permission) use (&$permissions){ |
|
60 | + $permissions[$permission->model][$permission->id] = $permission->name; |
|
61 | + }); |
|
62 | + } |
|
63 | 63 | |
64 | - return \Illuminate\Database\Eloquent\Collection::make($permissions); |
|
65 | - } |
|
64 | + return \Illuminate\Database\Eloquent\Collection::make($permissions); |
|
65 | + } |
|
66 | 66 | |
67 | - public static function boot() |
|
68 | - { |
|
69 | - parent::boot(); |
|
70 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
71 | - } |
|
67 | + public static function boot() |
|
68 | + { |
|
69 | + parent::boot(); |
|
70 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
71 | + } |
|
72 | 72 | } |
@@ -4,584 +4,584 @@ |
||
4 | 4 | |
5 | 5 | abstract class AbstractRepository implements RepositoryInterface |
6 | 6 | { |
7 | - /** |
|
8 | - * The model implementation. |
|
9 | - * |
|
10 | - * @var model |
|
11 | - */ |
|
12 | - public $model; |
|
7 | + /** |
|
8 | + * The model implementation. |
|
9 | + * |
|
10 | + * @var model |
|
11 | + */ |
|
12 | + public $model; |
|
13 | 13 | |
14 | - /** |
|
15 | - * The config implementation. |
|
16 | - * |
|
17 | - * @var config |
|
18 | - */ |
|
19 | - protected $config; |
|
14 | + /** |
|
15 | + * The config implementation. |
|
16 | + * |
|
17 | + * @var config |
|
18 | + */ |
|
19 | + protected $config; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Create new AbstractRepository instance. |
|
23 | - */ |
|
24 | - public function __construct() |
|
25 | - { |
|
26 | - $this->config = \CoreConfig::getConfig(); |
|
27 | - $this->model = \App::make($this->getModel()); |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Fetch all records with relations from the storage. |
|
32 | - * |
|
33 | - * @param array $relations |
|
34 | - * @param string $sortBy |
|
35 | - * @param boolean $desc |
|
36 | - * @param array $columns |
|
37 | - * @return collection |
|
38 | - */ |
|
39 | - public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
40 | - { |
|
41 | - $sort = $desc ? 'desc' : 'asc'; |
|
42 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Fetch all records with relations from storage in pages |
|
47 | - * that matche the given query. |
|
48 | - * |
|
49 | - * @param string $query |
|
50 | - * @param integer $perPage |
|
51 | - * @param array $relations |
|
52 | - * @param string $sortBy |
|
53 | - * @param boolean $desc |
|
54 | - * @param array $columns |
|
55 | - * @return collection |
|
56 | - */ |
|
57 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
58 | - { |
|
59 | - $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
60 | - $conditionColumns = $this->model->searchable; |
|
61 | - $sort = $desc ? 'desc' : 'asc'; |
|
62 | - |
|
63 | - /** |
|
64 | - * Construct the select conditions for the model. |
|
65 | - */ |
|
66 | - $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
67 | - |
|
68 | - if (count($conditionColumns)) |
|
69 | - { |
|
70 | - /** |
|
71 | - * Use the first element in the model columns to construct the first condition. |
|
72 | - */ |
|
73 | - $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Loop through the rest of the columns to construct or where conditions. |
|
78 | - */ |
|
79 | - foreach ($conditionColumns as $column) |
|
80 | - { |
|
81 | - $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Loop through the model relations. |
|
86 | - */ |
|
87 | - foreach ($relations as $relation) |
|
88 | - { |
|
89 | - /** |
|
90 | - * Remove the sub relation if exists. |
|
91 | - */ |
|
92 | - $relation = explode('.', $relation)[0]; |
|
93 | - |
|
94 | - /** |
|
95 | - * Try to fetch the relation repository from the core. |
|
96 | - */ |
|
97 | - if (\Core::$relation()) |
|
98 | - { |
|
99 | - /** |
|
100 | - * Construct the relation condition. |
|
101 | - */ |
|
102 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
103 | - |
|
104 | - $subModel->where(function ($q) use ($query, $relation){ |
|
105 | - |
|
106 | - /** |
|
107 | - * Get columns of the relation. |
|
108 | - */ |
|
109 | - $subConditionColumns = \Core::$relation()->model->searchable; |
|
110 | - |
|
111 | - if (count($subConditionColumns)) |
|
112 | - { |
|
113 | - /** |
|
114 | - * Use the first element in the relation model columns to construct the first condition. |
|
115 | - */ |
|
116 | - $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Loop through the rest of the columns to construct or where conditions. |
|
121 | - */ |
|
122 | - foreach ($subConditionColumns as $subConditionColumn) |
|
123 | - { |
|
124 | - $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
125 | - } |
|
126 | - }); |
|
127 | - |
|
128 | - }); |
|
129 | - } |
|
130 | - } |
|
131 | - }); |
|
21 | + /** |
|
22 | + * Create new AbstractRepository instance. |
|
23 | + */ |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + $this->config = \CoreConfig::getConfig(); |
|
27 | + $this->model = \App::make($this->getModel()); |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Fetch all records with relations from the storage. |
|
32 | + * |
|
33 | + * @param array $relations |
|
34 | + * @param string $sortBy |
|
35 | + * @param boolean $desc |
|
36 | + * @param array $columns |
|
37 | + * @return collection |
|
38 | + */ |
|
39 | + public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
40 | + { |
|
41 | + $sort = $desc ? 'desc' : 'asc'; |
|
42 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Fetch all records with relations from storage in pages |
|
47 | + * that matche the given query. |
|
48 | + * |
|
49 | + * @param string $query |
|
50 | + * @param integer $perPage |
|
51 | + * @param array $relations |
|
52 | + * @param string $sortBy |
|
53 | + * @param boolean $desc |
|
54 | + * @param array $columns |
|
55 | + * @return collection |
|
56 | + */ |
|
57 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
58 | + { |
|
59 | + $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
60 | + $conditionColumns = $this->model->searchable; |
|
61 | + $sort = $desc ? 'desc' : 'asc'; |
|
62 | + |
|
63 | + /** |
|
64 | + * Construct the select conditions for the model. |
|
65 | + */ |
|
66 | + $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
67 | + |
|
68 | + if (count($conditionColumns)) |
|
69 | + { |
|
70 | + /** |
|
71 | + * Use the first element in the model columns to construct the first condition. |
|
72 | + */ |
|
73 | + $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Loop through the rest of the columns to construct or where conditions. |
|
78 | + */ |
|
79 | + foreach ($conditionColumns as $column) |
|
80 | + { |
|
81 | + $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Loop through the model relations. |
|
86 | + */ |
|
87 | + foreach ($relations as $relation) |
|
88 | + { |
|
89 | + /** |
|
90 | + * Remove the sub relation if exists. |
|
91 | + */ |
|
92 | + $relation = explode('.', $relation)[0]; |
|
93 | + |
|
94 | + /** |
|
95 | + * Try to fetch the relation repository from the core. |
|
96 | + */ |
|
97 | + if (\Core::$relation()) |
|
98 | + { |
|
99 | + /** |
|
100 | + * Construct the relation condition. |
|
101 | + */ |
|
102 | + $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
103 | + |
|
104 | + $subModel->where(function ($q) use ($query, $relation){ |
|
105 | + |
|
106 | + /** |
|
107 | + * Get columns of the relation. |
|
108 | + */ |
|
109 | + $subConditionColumns = \Core::$relation()->model->searchable; |
|
110 | + |
|
111 | + if (count($subConditionColumns)) |
|
112 | + { |
|
113 | + /** |
|
114 | + * Use the first element in the relation model columns to construct the first condition. |
|
115 | + */ |
|
116 | + $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Loop through the rest of the columns to construct or where conditions. |
|
121 | + */ |
|
122 | + foreach ($subConditionColumns as $subConditionColumn) |
|
123 | + { |
|
124 | + $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
125 | + } |
|
126 | + }); |
|
127 | + |
|
128 | + }); |
|
129 | + } |
|
130 | + } |
|
131 | + }); |
|
132 | 132 | |
133 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
134 | - } |
|
133 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Fetch all records with relations from storage in pages. |
|
138 | - * |
|
139 | - * @param integer $perPage |
|
140 | - * @param array $relations |
|
141 | - * @param string $sortBy |
|
142 | - * @param boolean $desc |
|
143 | - * @param array $columns |
|
144 | - * @return collection |
|
145 | - */ |
|
146 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
147 | - { |
|
148 | - $sort = $desc ? 'desc' : 'asc'; |
|
149 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Fetch all records with relations based on |
|
154 | - * the given condition from storage in pages. |
|
155 | - * |
|
156 | - * @param array $conditions array of conditions |
|
157 | - * @param integer $perPage |
|
158 | - * @param array $relations |
|
159 | - * @param string $sortBy |
|
160 | - * @param boolean $desc |
|
161 | - * @param array $columns |
|
162 | - * @return collection |
|
163 | - */ |
|
164 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
165 | - { |
|
166 | - unset($conditions['page']); |
|
167 | - $conditions = $this->constructConditions($conditions); |
|
168 | - $sort = $desc ? 'desc' : 'asc'; |
|
169 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
170 | - } |
|
136 | + /** |
|
137 | + * Fetch all records with relations from storage in pages. |
|
138 | + * |
|
139 | + * @param integer $perPage |
|
140 | + * @param array $relations |
|
141 | + * @param string $sortBy |
|
142 | + * @param boolean $desc |
|
143 | + * @param array $columns |
|
144 | + * @return collection |
|
145 | + */ |
|
146 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
147 | + { |
|
148 | + $sort = $desc ? 'desc' : 'asc'; |
|
149 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Fetch all records with relations based on |
|
154 | + * the given condition from storage in pages. |
|
155 | + * |
|
156 | + * @param array $conditions array of conditions |
|
157 | + * @param integer $perPage |
|
158 | + * @param array $relations |
|
159 | + * @param string $sortBy |
|
160 | + * @param boolean $desc |
|
161 | + * @param array $columns |
|
162 | + * @return collection |
|
163 | + */ |
|
164 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
165 | + { |
|
166 | + unset($conditions['page']); |
|
167 | + $conditions = $this->constructConditions($conditions); |
|
168 | + $sort = $desc ? 'desc' : 'asc'; |
|
169 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * Save the given model to the storage. |
|
174 | - * |
|
175 | - * @param array $data |
|
176 | - * @param boolean $saveLog |
|
177 | - * @return void |
|
178 | - */ |
|
179 | - public function save(array $data, $saveLog = true) |
|
180 | - { |
|
181 | - $model = false; |
|
182 | - $modelClass = $this->model; |
|
183 | - $relations = []; |
|
184 | - |
|
185 | - \DB::transaction(function () use (&$model, &$relations, $data, $saveLog, $modelClass) { |
|
186 | - /** |
|
187 | - * If the id is present in the data then select the model for updating, |
|
188 | - * else create new model. |
|
189 | - * @var array |
|
190 | - */ |
|
191 | - $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
192 | - if ( ! $model) |
|
193 | - { |
|
194 | - \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Construct the model object with the given data, |
|
199 | - * and if there is a relation add it to relations array, |
|
200 | - * then save the model. |
|
201 | - */ |
|
202 | - foreach ($data as $key => $value) |
|
203 | - { |
|
204 | - /** |
|
205 | - * If the attribute is a relation. |
|
206 | - */ |
|
207 | - $relation = camel_case($key); |
|
208 | - if (method_exists($model, $relation) && \Core::$relation()) |
|
209 | - { |
|
210 | - |
|
211 | - /** |
|
212 | - * Check if the relation is a collection. |
|
213 | - */ |
|
214 | - if (class_basename($model->$relation) == 'Collection') |
|
215 | - { |
|
216 | - /** |
|
217 | - * If the relation has no value then marke the relation data |
|
218 | - * related to the model to be deleted. |
|
219 | - */ |
|
220 | - if ( ! $value || ! count($value)) |
|
221 | - { |
|
222 | - $relations[$relation] = 'delete'; |
|
223 | - } |
|
224 | - } |
|
225 | - if (is_array($value)) |
|
226 | - { |
|
227 | - /** |
|
228 | - * Loop through the relation data. |
|
229 | - */ |
|
230 | - foreach ($value as $attr => $val) |
|
231 | - { |
|
232 | - /** |
|
233 | - * Get the relation model. |
|
234 | - */ |
|
235 | - $relationBaseModel = \Core::$relation()->model; |
|
236 | - |
|
237 | - /** |
|
238 | - * Check if the relation is a collection. |
|
239 | - */ |
|
240 | - if (class_basename($model->$relation) == 'Collection') |
|
241 | - { |
|
242 | - /** |
|
243 | - * If the id is present in the data then select the relation model for updating, |
|
244 | - * else create new model. |
|
245 | - */ |
|
246 | - $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
247 | - |
|
248 | - /** |
|
249 | - * If model doesn't exists. |
|
250 | - */ |
|
251 | - if ( ! $relationModel) |
|
252 | - { |
|
253 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Loop through the relation attributes. |
|
258 | - */ |
|
259 | - foreach ($val as $attr => $val) |
|
260 | - { |
|
261 | - /** |
|
262 | - * Prevent the sub relations or attributes not in the fillable. |
|
263 | - */ |
|
264 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
265 | - { |
|
266 | - $relationModel->$attr = $val; |
|
267 | - } |
|
268 | - } |
|
269 | - $relations[$relation][] = $relationModel; |
|
270 | - } |
|
271 | - /** |
|
272 | - * If not collection. |
|
273 | - */ |
|
274 | - else |
|
275 | - { |
|
276 | - /** |
|
277 | - * Prevent the sub relations. |
|
278 | - */ |
|
279 | - if (gettype($val) !== 'object' && gettype($val) !== 'array') |
|
280 | - { |
|
281 | - /** |
|
282 | - * If the id is present in the data then select the relation model for updating, |
|
283 | - * else create new model. |
|
284 | - */ |
|
285 | - $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
286 | - |
|
287 | - /** |
|
288 | - * If model doesn't exists. |
|
289 | - */ |
|
290 | - if ( ! $relationModel) |
|
291 | - { |
|
292 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Prevent attributes not in the fillable. |
|
297 | - */ |
|
298 | - if (array_search($attr, $relationModel->getFillable(), true) !== false) |
|
299 | - { |
|
300 | - $relationModel->$attr = $val; |
|
301 | - $relations[$relation] = $relationModel; |
|
302 | - } |
|
303 | - } |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - /** |
|
309 | - * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
310 | - */ |
|
311 | - else if (array_search($key, $model->getFillable(), true) !== false) |
|
312 | - { |
|
313 | - $model->$key = $value; |
|
314 | - } |
|
315 | - } |
|
316 | - /** |
|
317 | - * Save the model. |
|
318 | - */ |
|
319 | - $model->save(); |
|
320 | - |
|
321 | - /** |
|
322 | - * Loop through the relations array. |
|
323 | - */ |
|
324 | - foreach ($relations as $key => $value) |
|
325 | - { |
|
326 | - /** |
|
327 | - * If the relation is marked for delete then delete it. |
|
328 | - */ |
|
329 | - if ($value == 'delete' && $model->$key()->count()) |
|
330 | - { |
|
331 | - $model->$key()->delete(); |
|
332 | - } |
|
333 | - /** |
|
334 | - * If the relation is an array. |
|
335 | - */ |
|
336 | - else if (gettype($value) == 'array') |
|
337 | - { |
|
338 | - $ids = []; |
|
339 | - /** |
|
340 | - * Loop through the relations. |
|
341 | - */ |
|
342 | - foreach ($value as $val) |
|
343 | - { |
|
344 | - switch (class_basename($model->$key())) |
|
345 | - { |
|
346 | - /** |
|
347 | - * If the relation is one to many then update it's foreign key with |
|
348 | - * the model id and save it then add its id to ids array to delete all |
|
349 | - * relations who's id isn't in the ids array. |
|
350 | - */ |
|
351 | - case 'HasMany': |
|
352 | - $foreignKeyName = explode('.', $model->$key()->getForeignKey())[1]; |
|
353 | - $val->$foreignKeyName = $model->id; |
|
354 | - $val->save(); |
|
355 | - $ids[] = $val->id; |
|
356 | - break; |
|
357 | - |
|
358 | - /** |
|
359 | - * If the relation is many to many then add it's id to the ids array to |
|
360 | - * attache these ids to the model. |
|
361 | - */ |
|
362 | - case 'BelongsToMany': |
|
363 | - $val->save(); |
|
364 | - $ids[] = $val->id; |
|
365 | - break; |
|
366 | - } |
|
367 | - } |
|
368 | - switch (class_basename($model->$key())) |
|
369 | - { |
|
370 | - /** |
|
371 | - * If the relation is one to many then delete all |
|
372 | - * relations who's id isn't in the ids array. |
|
373 | - */ |
|
374 | - case 'HasMany': |
|
375 | - $model->$key()->whereNotIn('id', $ids)->delete(); |
|
376 | - break; |
|
377 | - |
|
378 | - /** |
|
379 | - * If the relation is many to many then |
|
380 | - * detach the previous data and attach |
|
381 | - * the ids array to the model. |
|
382 | - */ |
|
383 | - case 'BelongsToMany': |
|
384 | - $model->$key()->detach(); |
|
385 | - $model->$key()->attach($ids); |
|
386 | - break; |
|
387 | - } |
|
388 | - } |
|
389 | - /** |
|
390 | - * If the relation isn't array. |
|
391 | - */ |
|
392 | - else |
|
393 | - { |
|
394 | - switch (class_basename($model->$key())) |
|
395 | - { |
|
396 | - /** |
|
397 | - * If the relation is one to many or one to one. |
|
398 | - */ |
|
399 | - case 'BelongsTo': |
|
400 | - $value->save(); |
|
401 | - $model->$key()->associate($value); |
|
402 | - $model->save(); |
|
403 | - break; |
|
404 | - } |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - $saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false; |
|
409 | - }); |
|
410 | - } |
|
172 | + /** |
|
173 | + * Save the given model to the storage. |
|
174 | + * |
|
175 | + * @param array $data |
|
176 | + * @param boolean $saveLog |
|
177 | + * @return void |
|
178 | + */ |
|
179 | + public function save(array $data, $saveLog = true) |
|
180 | + { |
|
181 | + $model = false; |
|
182 | + $modelClass = $this->model; |
|
183 | + $relations = []; |
|
184 | + |
|
185 | + \DB::transaction(function () use (&$model, &$relations, $data, $saveLog, $modelClass) { |
|
186 | + /** |
|
187 | + * If the id is present in the data then select the model for updating, |
|
188 | + * else create new model. |
|
189 | + * @var array |
|
190 | + */ |
|
191 | + $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
192 | + if ( ! $model) |
|
193 | + { |
|
194 | + \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Construct the model object with the given data, |
|
199 | + * and if there is a relation add it to relations array, |
|
200 | + * then save the model. |
|
201 | + */ |
|
202 | + foreach ($data as $key => $value) |
|
203 | + { |
|
204 | + /** |
|
205 | + * If the attribute is a relation. |
|
206 | + */ |
|
207 | + $relation = camel_case($key); |
|
208 | + if (method_exists($model, $relation) && \Core::$relation()) |
|
209 | + { |
|
210 | + |
|
211 | + /** |
|
212 | + * Check if the relation is a collection. |
|
213 | + */ |
|
214 | + if (class_basename($model->$relation) == 'Collection') |
|
215 | + { |
|
216 | + /** |
|
217 | + * If the relation has no value then marke the relation data |
|
218 | + * related to the model to be deleted. |
|
219 | + */ |
|
220 | + if ( ! $value || ! count($value)) |
|
221 | + { |
|
222 | + $relations[$relation] = 'delete'; |
|
223 | + } |
|
224 | + } |
|
225 | + if (is_array($value)) |
|
226 | + { |
|
227 | + /** |
|
228 | + * Loop through the relation data. |
|
229 | + */ |
|
230 | + foreach ($value as $attr => $val) |
|
231 | + { |
|
232 | + /** |
|
233 | + * Get the relation model. |
|
234 | + */ |
|
235 | + $relationBaseModel = \Core::$relation()->model; |
|
236 | + |
|
237 | + /** |
|
238 | + * Check if the relation is a collection. |
|
239 | + */ |
|
240 | + if (class_basename($model->$relation) == 'Collection') |
|
241 | + { |
|
242 | + /** |
|
243 | + * If the id is present in the data then select the relation model for updating, |
|
244 | + * else create new model. |
|
245 | + */ |
|
246 | + $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
247 | + |
|
248 | + /** |
|
249 | + * If model doesn't exists. |
|
250 | + */ |
|
251 | + if ( ! $relationModel) |
|
252 | + { |
|
253 | + \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Loop through the relation attributes. |
|
258 | + */ |
|
259 | + foreach ($val as $attr => $val) |
|
260 | + { |
|
261 | + /** |
|
262 | + * Prevent the sub relations or attributes not in the fillable. |
|
263 | + */ |
|
264 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
265 | + { |
|
266 | + $relationModel->$attr = $val; |
|
267 | + } |
|
268 | + } |
|
269 | + $relations[$relation][] = $relationModel; |
|
270 | + } |
|
271 | + /** |
|
272 | + * If not collection. |
|
273 | + */ |
|
274 | + else |
|
275 | + { |
|
276 | + /** |
|
277 | + * Prevent the sub relations. |
|
278 | + */ |
|
279 | + if (gettype($val) !== 'object' && gettype($val) !== 'array') |
|
280 | + { |
|
281 | + /** |
|
282 | + * If the id is present in the data then select the relation model for updating, |
|
283 | + * else create new model. |
|
284 | + */ |
|
285 | + $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
286 | + |
|
287 | + /** |
|
288 | + * If model doesn't exists. |
|
289 | + */ |
|
290 | + if ( ! $relationModel) |
|
291 | + { |
|
292 | + \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Prevent attributes not in the fillable. |
|
297 | + */ |
|
298 | + if (array_search($attr, $relationModel->getFillable(), true) !== false) |
|
299 | + { |
|
300 | + $relationModel->$attr = $val; |
|
301 | + $relations[$relation] = $relationModel; |
|
302 | + } |
|
303 | + } |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + /** |
|
309 | + * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
310 | + */ |
|
311 | + else if (array_search($key, $model->getFillable(), true) !== false) |
|
312 | + { |
|
313 | + $model->$key = $value; |
|
314 | + } |
|
315 | + } |
|
316 | + /** |
|
317 | + * Save the model. |
|
318 | + */ |
|
319 | + $model->save(); |
|
320 | + |
|
321 | + /** |
|
322 | + * Loop through the relations array. |
|
323 | + */ |
|
324 | + foreach ($relations as $key => $value) |
|
325 | + { |
|
326 | + /** |
|
327 | + * If the relation is marked for delete then delete it. |
|
328 | + */ |
|
329 | + if ($value == 'delete' && $model->$key()->count()) |
|
330 | + { |
|
331 | + $model->$key()->delete(); |
|
332 | + } |
|
333 | + /** |
|
334 | + * If the relation is an array. |
|
335 | + */ |
|
336 | + else if (gettype($value) == 'array') |
|
337 | + { |
|
338 | + $ids = []; |
|
339 | + /** |
|
340 | + * Loop through the relations. |
|
341 | + */ |
|
342 | + foreach ($value as $val) |
|
343 | + { |
|
344 | + switch (class_basename($model->$key())) |
|
345 | + { |
|
346 | + /** |
|
347 | + * If the relation is one to many then update it's foreign key with |
|
348 | + * the model id and save it then add its id to ids array to delete all |
|
349 | + * relations who's id isn't in the ids array. |
|
350 | + */ |
|
351 | + case 'HasMany': |
|
352 | + $foreignKeyName = explode('.', $model->$key()->getForeignKey())[1]; |
|
353 | + $val->$foreignKeyName = $model->id; |
|
354 | + $val->save(); |
|
355 | + $ids[] = $val->id; |
|
356 | + break; |
|
357 | + |
|
358 | + /** |
|
359 | + * If the relation is many to many then add it's id to the ids array to |
|
360 | + * attache these ids to the model. |
|
361 | + */ |
|
362 | + case 'BelongsToMany': |
|
363 | + $val->save(); |
|
364 | + $ids[] = $val->id; |
|
365 | + break; |
|
366 | + } |
|
367 | + } |
|
368 | + switch (class_basename($model->$key())) |
|
369 | + { |
|
370 | + /** |
|
371 | + * If the relation is one to many then delete all |
|
372 | + * relations who's id isn't in the ids array. |
|
373 | + */ |
|
374 | + case 'HasMany': |
|
375 | + $model->$key()->whereNotIn('id', $ids)->delete(); |
|
376 | + break; |
|
377 | + |
|
378 | + /** |
|
379 | + * If the relation is many to many then |
|
380 | + * detach the previous data and attach |
|
381 | + * the ids array to the model. |
|
382 | + */ |
|
383 | + case 'BelongsToMany': |
|
384 | + $model->$key()->detach(); |
|
385 | + $model->$key()->attach($ids); |
|
386 | + break; |
|
387 | + } |
|
388 | + } |
|
389 | + /** |
|
390 | + * If the relation isn't array. |
|
391 | + */ |
|
392 | + else |
|
393 | + { |
|
394 | + switch (class_basename($model->$key())) |
|
395 | + { |
|
396 | + /** |
|
397 | + * If the relation is one to many or one to one. |
|
398 | + */ |
|
399 | + case 'BelongsTo': |
|
400 | + $value->save(); |
|
401 | + $model->$key()->associate($value); |
|
402 | + $model->save(); |
|
403 | + break; |
|
404 | + } |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + $saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false; |
|
409 | + }); |
|
410 | + } |
|
411 | 411 | |
412 | - /** |
|
413 | - * Update record in the storage based on the given |
|
414 | - * condition. |
|
415 | - * |
|
416 | - * @param [type] $value condition value |
|
417 | - * @param array $data |
|
418 | - * @param string $attribute condition column name |
|
419 | - * @return void |
|
420 | - */ |
|
421 | - public function update($value, array $data, $attribute = 'id', $saveLog = true) |
|
422 | - { |
|
423 | - if ($attribute == 'id') |
|
424 | - { |
|
425 | - $model = $this->model->lockForUpdate()->find($value); |
|
426 | - $model ? $model->update($data) : 0; |
|
427 | - $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
428 | - } |
|
429 | - else |
|
430 | - { |
|
431 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
432 | - $model->update($data); |
|
433 | - $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
434 | - }); |
|
435 | - } |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Delete record from the storage based on the given |
|
440 | - * condition. |
|
441 | - * |
|
442 | - * @param var $value condition value |
|
443 | - * @param string $attribute condition column name |
|
444 | - * @return void |
|
445 | - */ |
|
446 | - public function delete($value, $attribute = 'id', $saveLog = true) |
|
447 | - { |
|
448 | - if ($attribute == 'id') |
|
449 | - { |
|
450 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
451 | - $model = $this->model->lockForUpdate()->find($value); |
|
452 | - if ( ! $model) |
|
453 | - { |
|
454 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
455 | - } |
|
412 | + /** |
|
413 | + * Update record in the storage based on the given |
|
414 | + * condition. |
|
415 | + * |
|
416 | + * @param [type] $value condition value |
|
417 | + * @param array $data |
|
418 | + * @param string $attribute condition column name |
|
419 | + * @return void |
|
420 | + */ |
|
421 | + public function update($value, array $data, $attribute = 'id', $saveLog = true) |
|
422 | + { |
|
423 | + if ($attribute == 'id') |
|
424 | + { |
|
425 | + $model = $this->model->lockForUpdate()->find($value); |
|
426 | + $model ? $model->update($data) : 0; |
|
427 | + $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
428 | + } |
|
429 | + else |
|
430 | + { |
|
431 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
432 | + $model->update($data); |
|
433 | + $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
434 | + }); |
|
435 | + } |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * Delete record from the storage based on the given |
|
440 | + * condition. |
|
441 | + * |
|
442 | + * @param var $value condition value |
|
443 | + * @param string $attribute condition column name |
|
444 | + * @return void |
|
445 | + */ |
|
446 | + public function delete($value, $attribute = 'id', $saveLog = true) |
|
447 | + { |
|
448 | + if ($attribute == 'id') |
|
449 | + { |
|
450 | + \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
451 | + $model = $this->model->lockForUpdate()->find($value); |
|
452 | + if ( ! $model) |
|
453 | + { |
|
454 | + \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
455 | + } |
|
456 | 456 | |
457 | - $model->delete(); |
|
458 | - $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
459 | - }); |
|
460 | - } |
|
461 | - else |
|
462 | - { |
|
463 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
464 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
465 | - $model->delete(); |
|
466 | - $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
467 | - }); |
|
468 | - }); |
|
469 | - } |
|
470 | - } |
|
457 | + $model->delete(); |
|
458 | + $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
459 | + }); |
|
460 | + } |
|
461 | + else |
|
462 | + { |
|
463 | + \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
464 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
465 | + $model->delete(); |
|
466 | + $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
467 | + }); |
|
468 | + }); |
|
469 | + } |
|
470 | + } |
|
471 | 471 | |
472 | - /** |
|
473 | - * Fetch records from the storage based on the given |
|
474 | - * id. |
|
475 | - * |
|
476 | - * @param integer $id |
|
477 | - * @param array $relations |
|
478 | - * @param array $columns |
|
479 | - * @return object |
|
480 | - */ |
|
481 | - public function find($id, $relations = [], $columns = array('*')) |
|
482 | - { |
|
483 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
|
484 | - } |
|
472 | + /** |
|
473 | + * Fetch records from the storage based on the given |
|
474 | + * id. |
|
475 | + * |
|
476 | + * @param integer $id |
|
477 | + * @param array $relations |
|
478 | + * @param array $columns |
|
479 | + * @return object |
|
480 | + */ |
|
481 | + public function find($id, $relations = [], $columns = array('*')) |
|
482 | + { |
|
483 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
|
484 | + } |
|
485 | 485 | |
486 | - /** |
|
487 | - * Fetch records from the storage based on the given |
|
488 | - * condition. |
|
489 | - * |
|
490 | - * @param array $conditions array of conditions |
|
491 | - * @param array $relations |
|
492 | - * @param string $sortBy |
|
493 | - * @param boolean $desc |
|
494 | - * @param array $columns |
|
495 | - * @return collection |
|
496 | - */ |
|
497 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
498 | - { |
|
499 | - $conditions = $this->constructConditions($conditions); |
|
500 | - $sort = $desc ? 'desc' : 'asc'; |
|
501 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * Fetch the first record from the storage based on the given |
|
506 | - * condition. |
|
507 | - * |
|
508 | - * @param array $conditions array of conditions |
|
509 | - * @param array $relations |
|
510 | - * @param array $columns |
|
511 | - * @return object |
|
512 | - */ |
|
513 | - public function first($conditions, $relations = [], $columns = array('*')) |
|
514 | - { |
|
515 | - $conditions = $this->constructConditions($conditions); |
|
516 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Build the conditions recursively for the retrieving methods. |
|
521 | - * @param array $conditions |
|
522 | - * @return array |
|
523 | - */ |
|
524 | - protected function constructConditions($conditions) |
|
525 | - { |
|
526 | - $conditionString = ''; |
|
527 | - $conditionValues = []; |
|
528 | - foreach ($conditions as $key => $value) |
|
529 | - { |
|
530 | - if ($key == 'and') |
|
531 | - { |
|
532 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
533 | - $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
534 | - } |
|
535 | - else if ($key == 'or') |
|
536 | - { |
|
537 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
538 | - $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
539 | - } |
|
540 | - else |
|
541 | - { |
|
542 | - if (is_array($value)) |
|
543 | - { |
|
544 | - $operator = $value['op']; |
|
545 | - if (strtolower($operator) == 'between') |
|
546 | - { |
|
547 | - $value1 = $value['val1']; |
|
548 | - $value2 = $value['val2']; |
|
549 | - } |
|
550 | - else |
|
551 | - { |
|
552 | - $value = $value['val']; |
|
553 | - } |
|
554 | - } |
|
555 | - else |
|
556 | - { |
|
557 | - $operator = '='; |
|
558 | - } |
|
486 | + /** |
|
487 | + * Fetch records from the storage based on the given |
|
488 | + * condition. |
|
489 | + * |
|
490 | + * @param array $conditions array of conditions |
|
491 | + * @param array $relations |
|
492 | + * @param string $sortBy |
|
493 | + * @param boolean $desc |
|
494 | + * @param array $columns |
|
495 | + * @return collection |
|
496 | + */ |
|
497 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
498 | + { |
|
499 | + $conditions = $this->constructConditions($conditions); |
|
500 | + $sort = $desc ? 'desc' : 'asc'; |
|
501 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Fetch the first record from the storage based on the given |
|
506 | + * condition. |
|
507 | + * |
|
508 | + * @param array $conditions array of conditions |
|
509 | + * @param array $relations |
|
510 | + * @param array $columns |
|
511 | + * @return object |
|
512 | + */ |
|
513 | + public function first($conditions, $relations = [], $columns = array('*')) |
|
514 | + { |
|
515 | + $conditions = $this->constructConditions($conditions); |
|
516 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Build the conditions recursively for the retrieving methods. |
|
521 | + * @param array $conditions |
|
522 | + * @return array |
|
523 | + */ |
|
524 | + protected function constructConditions($conditions) |
|
525 | + { |
|
526 | + $conditionString = ''; |
|
527 | + $conditionValues = []; |
|
528 | + foreach ($conditions as $key => $value) |
|
529 | + { |
|
530 | + if ($key == 'and') |
|
531 | + { |
|
532 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
533 | + $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
534 | + } |
|
535 | + else if ($key == 'or') |
|
536 | + { |
|
537 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
538 | + $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
539 | + } |
|
540 | + else |
|
541 | + { |
|
542 | + if (is_array($value)) |
|
543 | + { |
|
544 | + $operator = $value['op']; |
|
545 | + if (strtolower($operator) == 'between') |
|
546 | + { |
|
547 | + $value1 = $value['val1']; |
|
548 | + $value2 = $value['val2']; |
|
549 | + } |
|
550 | + else |
|
551 | + { |
|
552 | + $value = $value['val']; |
|
553 | + } |
|
554 | + } |
|
555 | + else |
|
556 | + { |
|
557 | + $operator = '='; |
|
558 | + } |
|
559 | 559 | |
560 | - if (strtolower($operator) == 'between') |
|
561 | - { |
|
562 | - $conditionString .= $key . '>=? and '; |
|
563 | - $conditionValues[] = $value1; |
|
564 | - |
|
565 | - $conditionString .= $key . '<=? {op} '; |
|
566 | - $conditionValues[] = $value2; |
|
567 | - } |
|
568 | - else |
|
569 | - { |
|
570 | - $conditionString .= $key . $operator . '? {op} '; |
|
571 | - $conditionValues[] = $value; |
|
572 | - } |
|
573 | - } |
|
574 | - } |
|
575 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
576 | - return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * Abstract method that return the necessary |
|
581 | - * information (full model namespace) |
|
582 | - * needed to preform the previous actions. |
|
583 | - * |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - abstract protected function getModel(); |
|
560 | + if (strtolower($operator) == 'between') |
|
561 | + { |
|
562 | + $conditionString .= $key . '>=? and '; |
|
563 | + $conditionValues[] = $value1; |
|
564 | + |
|
565 | + $conditionString .= $key . '<=? {op} '; |
|
566 | + $conditionValues[] = $value2; |
|
567 | + } |
|
568 | + else |
|
569 | + { |
|
570 | + $conditionString .= $key . $operator . '? {op} '; |
|
571 | + $conditionValues[] = $value; |
|
572 | + } |
|
573 | + } |
|
574 | + } |
|
575 | + $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
576 | + return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * Abstract method that return the necessary |
|
581 | + * information (full model namespace) |
|
582 | + * needed to preform the previous actions. |
|
583 | + * |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + abstract protected function getModel(); |
|
587 | 587 | } |
588 | 588 | \ No newline at end of file |
@@ -3,145 +3,145 @@ |
||
3 | 3 | class ErrorHandler |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * Array of error messags. |
|
8 | - */ |
|
9 | - private $messages = [ |
|
10 | - "en" => [ |
|
11 | - "unAuthorized" => "Please login before any action", |
|
12 | - "tokenExpired" => "Login token expired", |
|
13 | - "noPermissions" => "No permissions", |
|
14 | - "loginFailed" => "Wrong mail or password", |
|
15 | - "redisNotRunning" => "Your redis notification server isn't running", |
|
16 | - "dbQueryError" => "Please check the given inputes", |
|
17 | - "cannotCreateSetting" => "Can't create setting", |
|
18 | - "cannotUpdateSettingKey" => "Can't update setting key", |
|
19 | - "userIsBlocked" => "You have been blocked", |
|
20 | - "invalidResetToken" => "Reset password token is invalid", |
|
21 | - "invalidResetPassword" => "Reset password is invalid", |
|
22 | - "notFound" => "The requested {replace} not found", |
|
23 | - "generalError" => "Something went wrong", |
|
24 | - ], |
|
25 | - "ar" => [ |
|
26 | - "unAuthorized" => "من فضلك قم بتسجيل الدخول", |
|
27 | - "tokenExpired" => "انتهت صلاحية الدخول", |
|
28 | - "noPermissions" => "لا توجد صلاحية", |
|
29 | - "loginFailed" => "خطأ في البريد لاكتروني او كلمة المرور", |
|
30 | - "redisNotRunning" => "سيرفير الاشعارات لايعمل", |
|
31 | - "dbQueryError" => "خطا في البيانات", |
|
32 | - "cannotCreateSetting" => "لا يمكن اضافة اعدادات", |
|
33 | - "cannotUpdateSettingKey" => "لا يمكن تعديل اعدادات", |
|
34 | - "userIsBlocked" => "لقد تم حظرك", |
|
35 | - "invalidResetToken" => "رمز تعديل كلمة المرور خطا", |
|
36 | - "invalidResetPassword" => "خطا في نعديل كلمة المرور", |
|
37 | - "notFound" => "ال {replace} المطلوب غير موجود", |
|
38 | - "generalError" => "حدث خطا ما", |
|
39 | - ] |
|
40 | - ]; |
|
41 | - |
|
42 | - /** |
|
43 | - * The locale language. |
|
44 | - */ |
|
45 | - private $locale; |
|
46 | - |
|
47 | - public function __construct() |
|
48 | - { |
|
49 | - $locale = \Session::get('locale'); |
|
50 | - switch ($locale) |
|
51 | - { |
|
52 | - case 'en': |
|
53 | - $this->locale = 'en'; |
|
54 | - break; |
|
55 | - |
|
56 | - case 'ar': |
|
57 | - $this->locale = 'ar'; |
|
58 | - break; |
|
59 | - |
|
60 | - case 'all': |
|
61 | - $this->locale = 'en'; |
|
62 | - break; |
|
63 | - |
|
64 | - default: |
|
65 | - $this->locale = 'en'; |
|
66 | - break; |
|
67 | - } |
|
68 | - } |
|
69 | - |
|
70 | - public function unAuthorized() |
|
71 | - { |
|
72 | - $error = ['status' => 401, 'message' => $this->messages[$this->locale]['unAuthorized']]; |
|
73 | - abort($error['status'], $error['message']); |
|
74 | - } |
|
75 | - |
|
76 | - public function tokenExpired() |
|
77 | - { |
|
78 | - $error = ['status' => 403, 'message' => $this->messages[$this->locale]['tokenExpired']]; |
|
79 | - abort($error['status'], $error['message']); |
|
80 | - } |
|
81 | - |
|
82 | - public function noPermissions() |
|
83 | - { |
|
84 | - $error = ['status' => 403, 'message' => $this->messages[$this->locale]['noPermissions']]; |
|
85 | - abort($error['status'], $error['message']); |
|
86 | - } |
|
87 | - |
|
88 | - public function loginFailed() |
|
89 | - { |
|
90 | - $error = ['status' => 400, 'message' => $this->messages[$this->locale]['loginFailed']]; |
|
91 | - abort($error['status'], $error['message']); |
|
92 | - } |
|
93 | - |
|
94 | - public function redisNotRunning() |
|
95 | - { |
|
96 | - $error = ['status' => 400, 'message' => $this->messages[$this->locale]['redisNotRunning']]; |
|
97 | - abort($error['status'], $error['message']); |
|
98 | - } |
|
99 | - |
|
100 | - public function dbQueryError() |
|
101 | - { |
|
102 | - $error = ['status' => 400, 'message' => $this->messages[$this->locale]['dbQueryError']]; |
|
103 | - abort($error['status'], $error['message']); |
|
104 | - } |
|
105 | - |
|
106 | - public function cannotCreateSetting() |
|
107 | - { |
|
108 | - $error = ['status' => 400, 'message' => $this->messages[$this->locale]['cannotCreateSetting']]; |
|
109 | - abort($error['status'], $error['message']); |
|
110 | - } |
|
111 | - |
|
112 | - public function cannotUpdateSettingKey() |
|
113 | - { |
|
114 | - $error = ['status' => 400, 'message' => $this->messages[$this->locale]['cannotUpdateSettingKey']]; |
|
115 | - abort($error['status'], $error['message']); |
|
116 | - } |
|
117 | - |
|
118 | - public function userIsBlocked() |
|
119 | - { |
|
120 | - $error = ['status' => 403, 'message' => $this->messages[$this->locale]['userIsBlocked']]; |
|
121 | - abort($error['status'], $error['message']); |
|
122 | - } |
|
123 | - |
|
124 | - public function invalidResetToken() |
|
125 | - { |
|
126 | - $error = ['status' => 400, 'message' => $this->messages[$this->locale]['invalidResetToken']]; |
|
127 | - abort($error['status'], $error['message']); |
|
128 | - } |
|
129 | - |
|
130 | - public function invalidResetPassword() |
|
131 | - { |
|
132 | - $error = ['status' => 400, 'message' => $this->messages[$this->locale]['invalidResetPassword']]; |
|
133 | - abort($error['status'], $error['message']); |
|
134 | - } |
|
135 | - |
|
136 | - public function notFound($text) |
|
137 | - { |
|
138 | - $error = ['status' => 404, 'message' => str_replace($this->messages[$this->locale]['notFound'], '{replace}', $text)]; |
|
139 | - abort($error['status'], $error['message']); |
|
140 | - } |
|
141 | - |
|
142 | - public function generalError() |
|
143 | - { |
|
144 | - $error = ['status' => 404, 'message' => $this->messages[$this->locale]['generalError']]; |
|
145 | - abort($error['status'], $error['message']); |
|
146 | - } |
|
6 | + /** |
|
7 | + * Array of error messags. |
|
8 | + */ |
|
9 | + private $messages = [ |
|
10 | + "en" => [ |
|
11 | + "unAuthorized" => "Please login before any action", |
|
12 | + "tokenExpired" => "Login token expired", |
|
13 | + "noPermissions" => "No permissions", |
|
14 | + "loginFailed" => "Wrong mail or password", |
|
15 | + "redisNotRunning" => "Your redis notification server isn't running", |
|
16 | + "dbQueryError" => "Please check the given inputes", |
|
17 | + "cannotCreateSetting" => "Can't create setting", |
|
18 | + "cannotUpdateSettingKey" => "Can't update setting key", |
|
19 | + "userIsBlocked" => "You have been blocked", |
|
20 | + "invalidResetToken" => "Reset password token is invalid", |
|
21 | + "invalidResetPassword" => "Reset password is invalid", |
|
22 | + "notFound" => "The requested {replace} not found", |
|
23 | + "generalError" => "Something went wrong", |
|
24 | + ], |
|
25 | + "ar" => [ |
|
26 | + "unAuthorized" => "من فضلك قم بتسجيل الدخول", |
|
27 | + "tokenExpired" => "انتهت صلاحية الدخول", |
|
28 | + "noPermissions" => "لا توجد صلاحية", |
|
29 | + "loginFailed" => "خطأ في البريد لاكتروني او كلمة المرور", |
|
30 | + "redisNotRunning" => "سيرفير الاشعارات لايعمل", |
|
31 | + "dbQueryError" => "خطا في البيانات", |
|
32 | + "cannotCreateSetting" => "لا يمكن اضافة اعدادات", |
|
33 | + "cannotUpdateSettingKey" => "لا يمكن تعديل اعدادات", |
|
34 | + "userIsBlocked" => "لقد تم حظرك", |
|
35 | + "invalidResetToken" => "رمز تعديل كلمة المرور خطا", |
|
36 | + "invalidResetPassword" => "خطا في نعديل كلمة المرور", |
|
37 | + "notFound" => "ال {replace} المطلوب غير موجود", |
|
38 | + "generalError" => "حدث خطا ما", |
|
39 | + ] |
|
40 | + ]; |
|
41 | + |
|
42 | + /** |
|
43 | + * The locale language. |
|
44 | + */ |
|
45 | + private $locale; |
|
46 | + |
|
47 | + public function __construct() |
|
48 | + { |
|
49 | + $locale = \Session::get('locale'); |
|
50 | + switch ($locale) |
|
51 | + { |
|
52 | + case 'en': |
|
53 | + $this->locale = 'en'; |
|
54 | + break; |
|
55 | + |
|
56 | + case 'ar': |
|
57 | + $this->locale = 'ar'; |
|
58 | + break; |
|
59 | + |
|
60 | + case 'all': |
|
61 | + $this->locale = 'en'; |
|
62 | + break; |
|
63 | + |
|
64 | + default: |
|
65 | + $this->locale = 'en'; |
|
66 | + break; |
|
67 | + } |
|
68 | + } |
|
69 | + |
|
70 | + public function unAuthorized() |
|
71 | + { |
|
72 | + $error = ['status' => 401, 'message' => $this->messages[$this->locale]['unAuthorized']]; |
|
73 | + abort($error['status'], $error['message']); |
|
74 | + } |
|
75 | + |
|
76 | + public function tokenExpired() |
|
77 | + { |
|
78 | + $error = ['status' => 403, 'message' => $this->messages[$this->locale]['tokenExpired']]; |
|
79 | + abort($error['status'], $error['message']); |
|
80 | + } |
|
81 | + |
|
82 | + public function noPermissions() |
|
83 | + { |
|
84 | + $error = ['status' => 403, 'message' => $this->messages[$this->locale]['noPermissions']]; |
|
85 | + abort($error['status'], $error['message']); |
|
86 | + } |
|
87 | + |
|
88 | + public function loginFailed() |
|
89 | + { |
|
90 | + $error = ['status' => 400, 'message' => $this->messages[$this->locale]['loginFailed']]; |
|
91 | + abort($error['status'], $error['message']); |
|
92 | + } |
|
93 | + |
|
94 | + public function redisNotRunning() |
|
95 | + { |
|
96 | + $error = ['status' => 400, 'message' => $this->messages[$this->locale]['redisNotRunning']]; |
|
97 | + abort($error['status'], $error['message']); |
|
98 | + } |
|
99 | + |
|
100 | + public function dbQueryError() |
|
101 | + { |
|
102 | + $error = ['status' => 400, 'message' => $this->messages[$this->locale]['dbQueryError']]; |
|
103 | + abort($error['status'], $error['message']); |
|
104 | + } |
|
105 | + |
|
106 | + public function cannotCreateSetting() |
|
107 | + { |
|
108 | + $error = ['status' => 400, 'message' => $this->messages[$this->locale]['cannotCreateSetting']]; |
|
109 | + abort($error['status'], $error['message']); |
|
110 | + } |
|
111 | + |
|
112 | + public function cannotUpdateSettingKey() |
|
113 | + { |
|
114 | + $error = ['status' => 400, 'message' => $this->messages[$this->locale]['cannotUpdateSettingKey']]; |
|
115 | + abort($error['status'], $error['message']); |
|
116 | + } |
|
117 | + |
|
118 | + public function userIsBlocked() |
|
119 | + { |
|
120 | + $error = ['status' => 403, 'message' => $this->messages[$this->locale]['userIsBlocked']]; |
|
121 | + abort($error['status'], $error['message']); |
|
122 | + } |
|
123 | + |
|
124 | + public function invalidResetToken() |
|
125 | + { |
|
126 | + $error = ['status' => 400, 'message' => $this->messages[$this->locale]['invalidResetToken']]; |
|
127 | + abort($error['status'], $error['message']); |
|
128 | + } |
|
129 | + |
|
130 | + public function invalidResetPassword() |
|
131 | + { |
|
132 | + $error = ['status' => 400, 'message' => $this->messages[$this->locale]['invalidResetPassword']]; |
|
133 | + abort($error['status'], $error['message']); |
|
134 | + } |
|
135 | + |
|
136 | + public function notFound($text) |
|
137 | + { |
|
138 | + $error = ['status' => 404, 'message' => str_replace($this->messages[$this->locale]['notFound'], '{replace}', $text)]; |
|
139 | + abort($error['status'], $error['message']); |
|
140 | + } |
|
141 | + |
|
142 | + public function generalError() |
|
143 | + { |
|
144 | + $error = ['status' => 404, 'message' => $this->messages[$this->locale]['generalError']]; |
|
145 | + abort($error['status'], $error['message']); |
|
146 | + } |
|
147 | 147 | } |
148 | 148 | \ No newline at end of file |