@@ -4,13 +4,13 @@ |
||
4 | 4 | { |
5 | 5 | /** |
6 | 6 | * Construct the repository class name based on |
7 | - * the method name called, search in the |
|
8 | - * given namespaces for the class and |
|
9 | - * return an instance. |
|
10 | - * |
|
11 | - * @param string $name the called method name |
|
12 | - * @param array $arguments the method arguments |
|
13 | - * @return object |
|
14 | - */ |
|
7 | + * the method name called, search in the |
|
8 | + * given namespaces for the class and |
|
9 | + * return an instance. |
|
10 | + * |
|
11 | + * @param string $name the called method name |
|
12 | + * @param array $arguments the method arguments |
|
13 | + * @return object |
|
14 | + */ |
|
15 | 15 | public function __call($name, $arguments); |
16 | 16 | } |
17 | 17 | \ No newline at end of file |
@@ -8,9 +8,9 @@ |
||
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 | } |
@@ -22,15 +22,15 @@ |
||
22 | 22 | "); |
23 | 23 | |
24 | 24 | DB::table('reports')->insert( |
25 | - [ |
|
26 | - [ |
|
25 | + [ |
|
26 | + [ |
|
27 | 27 | 'report_name' => 'admin_count', |
28 | 28 | 'view_name' => 'admin_count', |
29 | 29 | 'created_at' => \DB::raw('NOW()'), |
30 | 30 | 'updated_at' => \DB::raw('NOW()') |
31 | - ] |
|
32 | - ] |
|
33 | - ); |
|
31 | + ] |
|
32 | + ] |
|
33 | + ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -18,7 +18,7 @@ |
||
18 | 18 | $table->string('view_name',100); |
19 | 19 | $table->softDeletes(); |
20 | 20 | $table->timestamps(); |
21 | - }); |
|
21 | + }); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -13,19 +13,19 @@ |
||
13 | 13 | public function up() |
14 | 14 | { |
15 | 15 | Schema::create('groups', function (Blueprint $table) { |
16 | - $table->increments('id'); |
|
17 | - $table->string('name',100)->unique(); |
|
18 | - $table->softDeletes(); |
|
19 | - $table->timestamps(); |
|
20 | - }); |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name',100)->unique(); |
|
18 | + $table->softDeletes(); |
|
19 | + $table->timestamps(); |
|
20 | + }); |
|
21 | 21 | |
22 | - Schema::create('users_groups', function (Blueprint $table) { |
|
23 | - $table->increments('id'); |
|
24 | - $table->integer('user_id'); |
|
25 | - $table->integer('group_id'); |
|
26 | - $table->softDeletes(); |
|
27 | - $table->timestamps(); |
|
28 | - }); |
|
22 | + Schema::create('users_groups', function (Blueprint $table) { |
|
23 | + $table->increments('id'); |
|
24 | + $table->integer('user_id'); |
|
25 | + $table->integer('group_id'); |
|
26 | + $table->softDeletes(); |
|
27 | + $table->timestamps(); |
|
28 | + }); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -12,21 +12,21 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('permissions', function (Blueprint $table) { |
|
16 | - $table->increments('id'); |
|
17 | - $table->string('name',100); |
|
18 | - $table->string('model',100); |
|
19 | - $table->softDeletes(); |
|
20 | - $table->timestamps(); |
|
21 | - $table->unique(array('name', 'model')); |
|
22 | - }); |
|
23 | - Schema::create('groups_permissions', function (Blueprint $table) { |
|
24 | - $table->increments('id'); |
|
25 | - $table->integer('group_id'); |
|
26 | - $table->integer('permission_id'); |
|
27 | - $table->softDeletes(); |
|
28 | - $table->timestamps(); |
|
29 | - }); |
|
15 | + Schema::create('permissions', function (Blueprint $table) { |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name',100); |
|
18 | + $table->string('model',100); |
|
19 | + $table->softDeletes(); |
|
20 | + $table->timestamps(); |
|
21 | + $table->unique(array('name', 'model')); |
|
22 | + }); |
|
23 | + Schema::create('groups_permissions', function (Blueprint $table) { |
|
24 | + $table->increments('id'); |
|
25 | + $table->integer('group_id'); |
|
26 | + $table->integer('permission_id'); |
|
27 | + $table->softDeletes(); |
|
28 | + $table->timestamps(); |
|
29 | + }); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -7,10 +7,10 @@ |
||
7 | 7 | |
8 | 8 | class PermissionsController 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 = 'permissions'; |
|
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 = 'permissions'; |
|
16 | 16 | } |
@@ -2,17 +2,17 @@ |
||
2 | 2 | |
3 | 3 | class Logging |
4 | 4 | { |
5 | - public function saveLog($action, $item_name, $item_type, $item_id) |
|
6 | - { |
|
7 | - if (\Core::logs() && $item_name !== 'Log') |
|
8 | - { |
|
9 | - \Core::logs()->save([ |
|
10 | - 'action' => $action, |
|
11 | - 'item_name' => $item_name, |
|
12 | - 'item_type' => $item_type, |
|
13 | - 'item_id' => $item_id, |
|
14 | - 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
15 | - ], false, false); |
|
16 | - } |
|
17 | - } |
|
5 | + public function saveLog($action, $item_name, $item_type, $item_id) |
|
6 | + { |
|
7 | + if (\Core::logs() && $item_name !== 'Log') |
|
8 | + { |
|
9 | + \Core::logs()->save([ |
|
10 | + 'action' => $action, |
|
11 | + 'item_name' => $item_name, |
|
12 | + 'item_type' => $item_type, |
|
13 | + 'item_id' => $item_id, |
|
14 | + 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
15 | + ], false, false); |
|
16 | + } |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | \ No newline at end of file |
@@ -170,8 +170,7 @@ |
||
170 | 170 | if ($request->has('id')) |
171 | 171 | { |
172 | 172 | $rule = str_replace('{id}', $request->get('id'), $rule); |
173 | - } |
|
174 | - else |
|
173 | + } else |
|
175 | 174 | { |
176 | 175 | $rule = str_replace(',{id}', '', $rule); |
177 | 176 | } |
@@ -6,298 +6,298 @@ |
||
6 | 6 | |
7 | 7 | class BaseApiController extends Controller |
8 | 8 | { |
9 | - /** |
|
10 | - * The config implementation. |
|
11 | - * |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - protected $config; |
|
9 | + /** |
|
10 | + * The config implementation. |
|
11 | + * |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + protected $config; |
|
15 | 15 | |
16 | - /** |
|
17 | - * The relations implementation. |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected $relations; |
|
16 | + /** |
|
17 | + * The relations implementation. |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected $relations; |
|
22 | 22 | |
23 | - /** |
|
24 | - * The repo implementation. |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $repo; |
|
23 | + /** |
|
24 | + * The repo implementation. |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $repo; |
|
29 | 29 | |
30 | - public function __construct() |
|
31 | - { |
|
32 | - $this->config = \CoreConfig::getConfig(); |
|
33 | - $this->model = property_exists($this, 'model') ? $this->model : false; |
|
34 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
35 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
36 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
37 | - $this->repo = call_user_func_array("\Core::{$this->model}", []); |
|
38 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + $this->config = \CoreConfig::getConfig(); |
|
33 | + $this->model = property_exists($this, 'model') ? $this->model : false; |
|
34 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
35 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
36 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
37 | + $this->repo = call_user_func_array("\Core::{$this->model}", []); |
|
38 | + $route = explode('@',\Route::currentRouteAction())[1]; |
|
39 | 39 | |
40 | - $this->checkPermission($route); |
|
41 | - $this->setRelations($route); |
|
42 | - $this->setSessions(); |
|
43 | - } |
|
40 | + $this->checkPermission($route); |
|
41 | + $this->setRelations($route); |
|
42 | + $this->setSessions(); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Fetch all records with relations from storage. |
|
47 | - * |
|
48 | - * @param string $sortBy The name of the column to sort by. |
|
49 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
50 | - * @return \Illuminate\Http\Response |
|
51 | - */ |
|
52 | - public function index($sortBy = 'created_at', $desc = 1) |
|
53 | - { |
|
54 | - if ($this->repo) |
|
55 | - { |
|
56 | - return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200); |
|
57 | - } |
|
58 | - } |
|
45 | + /** |
|
46 | + * Fetch all records with relations from storage. |
|
47 | + * |
|
48 | + * @param string $sortBy The name of the column to sort by. |
|
49 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
50 | + * @return \Illuminate\Http\Response |
|
51 | + */ |
|
52 | + public function index($sortBy = 'created_at', $desc = 1) |
|
53 | + { |
|
54 | + if ($this->repo) |
|
55 | + { |
|
56 | + return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Fetch the single object with relations from storage. |
|
62 | - * |
|
63 | - * @param integer $id Id of the requested model. |
|
64 | - * @return \Illuminate\Http\Response |
|
65 | - */ |
|
66 | - public function find($id) |
|
67 | - { |
|
68 | - if ($this->repo) |
|
69 | - { |
|
70 | - return \Response::json($this->repo->find($id, $this->relations), 200); |
|
71 | - } |
|
72 | - } |
|
60 | + /** |
|
61 | + * Fetch the single object with relations from storage. |
|
62 | + * |
|
63 | + * @param integer $id Id of the requested model. |
|
64 | + * @return \Illuminate\Http\Response |
|
65 | + */ |
|
66 | + public function find($id) |
|
67 | + { |
|
68 | + if ($this->repo) |
|
69 | + { |
|
70 | + return \Response::json($this->repo->find($id, $this->relations), 200); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Paginate all records with relations from storage |
|
76 | - * that matche the given query. |
|
77 | - * |
|
78 | - * @param string $query The search text. |
|
79 | - * @param integer $perPage Number of rows per page default 15. |
|
80 | - * @param string $sortBy The name of the column to sort by. |
|
81 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
82 | - * @return \Illuminate\Http\Response |
|
83 | - */ |
|
84 | - public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
85 | - { |
|
86 | - if ($this->repo) |
|
87 | - { |
|
88 | - return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200); |
|
89 | - } |
|
90 | - } |
|
74 | + /** |
|
75 | + * Paginate all records with relations from storage |
|
76 | + * that matche the given query. |
|
77 | + * |
|
78 | + * @param string $query The search text. |
|
79 | + * @param integer $perPage Number of rows per page default 15. |
|
80 | + * @param string $sortBy The name of the column to sort by. |
|
81 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
82 | + * @return \Illuminate\Http\Response |
|
83 | + */ |
|
84 | + public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
85 | + { |
|
86 | + if ($this->repo) |
|
87 | + { |
|
88 | + return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Fetch records from the storage based on the given |
|
94 | - * condition. |
|
95 | - * |
|
96 | - * @param \Illuminate\Http\Request $request |
|
97 | - * @param string $sortBy The name of the column to sort by. |
|
98 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
99 | - * @return \Illuminate\Http\Response |
|
100 | - */ |
|
101 | - public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
102 | - { |
|
103 | - if ($this->repo) |
|
104 | - { |
|
105 | - return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200); |
|
106 | - } |
|
107 | - } |
|
92 | + /** |
|
93 | + * Fetch records from the storage based on the given |
|
94 | + * condition. |
|
95 | + * |
|
96 | + * @param \Illuminate\Http\Request $request |
|
97 | + * @param string $sortBy The name of the column to sort by. |
|
98 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
99 | + * @return \Illuminate\Http\Response |
|
100 | + */ |
|
101 | + public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
102 | + { |
|
103 | + if ($this->repo) |
|
104 | + { |
|
105 | + return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200); |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Fetch the first record from the storage based on the given |
|
111 | - * condition. |
|
112 | - * |
|
113 | - * @param \Illuminate\Http\Request $request |
|
114 | - * @return \Illuminate\Http\Response |
|
115 | - */ |
|
116 | - public function first(Request $request) |
|
117 | - { |
|
118 | - if ($this->repo) |
|
119 | - { |
|
120 | - return \Response::json($this->repo->first($request->all(), $this->relations), 200); |
|
121 | - } |
|
122 | - } |
|
109 | + /** |
|
110 | + * Fetch the first record from the storage based on the given |
|
111 | + * condition. |
|
112 | + * |
|
113 | + * @param \Illuminate\Http\Request $request |
|
114 | + * @return \Illuminate\Http\Response |
|
115 | + */ |
|
116 | + public function first(Request $request) |
|
117 | + { |
|
118 | + if ($this->repo) |
|
119 | + { |
|
120 | + return \Response::json($this->repo->first($request->all(), $this->relations), 200); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Paginate all records with relations from storage. |
|
126 | - * |
|
127 | - * @param integer $perPage Number of rows per page default 15. |
|
128 | - * @param string $sortBy The name of the column to sort by. |
|
129 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
130 | - * @return \Illuminate\Http\Response |
|
131 | - */ |
|
132 | - public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
133 | - { |
|
134 | - if ($this->repo) |
|
135 | - { |
|
136 | - return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200); |
|
137 | - } |
|
138 | - } |
|
124 | + /** |
|
125 | + * Paginate all records with relations from storage. |
|
126 | + * |
|
127 | + * @param integer $perPage Number of rows per page default 15. |
|
128 | + * @param string $sortBy The name of the column to sort by. |
|
129 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
130 | + * @return \Illuminate\Http\Response |
|
131 | + */ |
|
132 | + public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
133 | + { |
|
134 | + if ($this->repo) |
|
135 | + { |
|
136 | + return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200); |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Fetch all records with relations based on |
|
142 | - * the given condition from storage in pages. |
|
143 | - * |
|
144 | - * @param \Illuminate\Http\Request $request |
|
145 | - * @param integer $perPage Number of rows per page default 15. |
|
146 | - * @param string $sortBy The name of the column to sort by. |
|
147 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
148 | - * @return \Illuminate\Http\Response |
|
149 | - */ |
|
150 | - public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
151 | - { |
|
152 | - if ($this->repo) |
|
153 | - { |
|
154 | - return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200); |
|
155 | - } |
|
156 | - } |
|
140 | + /** |
|
141 | + * Fetch all records with relations based on |
|
142 | + * the given condition from storage in pages. |
|
143 | + * |
|
144 | + * @param \Illuminate\Http\Request $request |
|
145 | + * @param integer $perPage Number of rows per page default 15. |
|
146 | + * @param string $sortBy The name of the column to sort by. |
|
147 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
148 | + * @return \Illuminate\Http\Response |
|
149 | + */ |
|
150 | + public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
151 | + { |
|
152 | + if ($this->repo) |
|
153 | + { |
|
154 | + return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200); |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Save the given model to storage. |
|
160 | - * |
|
161 | - * @param \Illuminate\Http\Request $request |
|
162 | - * @return \Illuminate\Http\Response |
|
163 | - */ |
|
164 | - public function save(Request $request) |
|
165 | - { |
|
166 | - foreach ($this->validationRules as &$rule) |
|
167 | - { |
|
168 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
169 | - { |
|
170 | - $rule .= ',deleted_at,NULL'; |
|
171 | - } |
|
158 | + /** |
|
159 | + * Save the given model to storage. |
|
160 | + * |
|
161 | + * @param \Illuminate\Http\Request $request |
|
162 | + * @return \Illuminate\Http\Response |
|
163 | + */ |
|
164 | + public function save(Request $request) |
|
165 | + { |
|
166 | + foreach ($this->validationRules as &$rule) |
|
167 | + { |
|
168 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
169 | + { |
|
170 | + $rule .= ',deleted_at,NULL'; |
|
171 | + } |
|
172 | 172 | |
173 | - if ($request->has('id')) |
|
174 | - { |
|
175 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
176 | - } |
|
177 | - else |
|
178 | - { |
|
179 | - $rule = str_replace(',{id}', '', $rule); |
|
180 | - } |
|
181 | - } |
|
173 | + if ($request->has('id')) |
|
174 | + { |
|
175 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
176 | + } |
|
177 | + else |
|
178 | + { |
|
179 | + $rule = str_replace(',{id}', '', $rule); |
|
180 | + } |
|
181 | + } |
|
182 | 182 | |
183 | - $this->validate($request, $this->validationRules); |
|
183 | + $this->validate($request, $this->validationRules); |
|
184 | 184 | |
185 | - if ($this->repo) |
|
186 | - { |
|
187 | - return \Response::json($this->repo->save($request->all()), 200); |
|
188 | - } |
|
189 | - } |
|
185 | + if ($this->repo) |
|
186 | + { |
|
187 | + return \Response::json($this->repo->save($request->all()), 200); |
|
188 | + } |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Delete by the given id from storage. |
|
193 | - * |
|
194 | - * @param integer $id Id of the deleted model. |
|
195 | - * @return \Illuminate\Http\Response |
|
196 | - */ |
|
197 | - public function delete($id) |
|
198 | - { |
|
199 | - if ($this->repo) |
|
200 | - { |
|
201 | - return \Response::json($this->repo->delete($id), 200); |
|
202 | - } |
|
203 | - } |
|
191 | + /** |
|
192 | + * Delete by the given id from storage. |
|
193 | + * |
|
194 | + * @param integer $id Id of the deleted model. |
|
195 | + * @return \Illuminate\Http\Response |
|
196 | + */ |
|
197 | + public function delete($id) |
|
198 | + { |
|
199 | + if ($this->repo) |
|
200 | + { |
|
201 | + return \Response::json($this->repo->delete($id), 200); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Return the deleted models in pages based on the given conditions. |
|
207 | - * |
|
208 | - * @param \Illuminate\Http\Request $request |
|
209 | - * @param integer $perPage Number of rows per page default 15. |
|
210 | - * @param string $sortBy The name of the column to sort by. |
|
211 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
212 | - * @return \Illuminate\Http\Response |
|
213 | - */ |
|
214 | - public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
215 | - { |
|
216 | - return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200); |
|
217 | - } |
|
205 | + /** |
|
206 | + * Return the deleted models in pages based on the given conditions. |
|
207 | + * |
|
208 | + * @param \Illuminate\Http\Request $request |
|
209 | + * @param integer $perPage Number of rows per page default 15. |
|
210 | + * @param string $sortBy The name of the column to sort by. |
|
211 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
212 | + * @return \Illuminate\Http\Response |
|
213 | + */ |
|
214 | + public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
215 | + { |
|
216 | + return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Restore the deleted model. |
|
221 | - * |
|
222 | - * @param integer $id Id of the restored model. |
|
223 | - * @return \Illuminate\Http\Response |
|
224 | - */ |
|
225 | - public function restore($id) |
|
226 | - { |
|
227 | - if ($this->repo) |
|
228 | - { |
|
229 | - return \Response::json($this->repo->restore($id), 200); |
|
230 | - } |
|
231 | - } |
|
219 | + /** |
|
220 | + * Restore the deleted model. |
|
221 | + * |
|
222 | + * @param integer $id Id of the restored model. |
|
223 | + * @return \Illuminate\Http\Response |
|
224 | + */ |
|
225 | + public function restore($id) |
|
226 | + { |
|
227 | + if ($this->repo) |
|
228 | + { |
|
229 | + return \Response::json($this->repo->restore($id), 200); |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Check if the logged in user can do the given permission. |
|
235 | - * |
|
236 | - * @param string $permission |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - private function checkPermission($permission) |
|
240 | - { |
|
241 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
242 | - if ( ! in_array($permission, $this->skipLoginCheck)) |
|
243 | - { |
|
244 | - $user = \JWTAuth::parseToken()->authenticate(); |
|
245 | - if ($user->blocked) |
|
246 | - { |
|
247 | - \ErrorHandler::userIsBlocked(); |
|
248 | - } |
|
233 | + /** |
|
234 | + * Check if the logged in user can do the given permission. |
|
235 | + * |
|
236 | + * @param string $permission |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + private function checkPermission($permission) |
|
240 | + { |
|
241 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
242 | + if ( ! in_array($permission, $this->skipLoginCheck)) |
|
243 | + { |
|
244 | + $user = \JWTAuth::parseToken()->authenticate(); |
|
245 | + if ($user->blocked) |
|
246 | + { |
|
247 | + \ErrorHandler::userIsBlocked(); |
|
248 | + } |
|
249 | 249 | |
250 | - if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
251 | - { |
|
252 | - \ErrorHandler::noPermissions(); |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
250 | + if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
251 | + { |
|
252 | + \ErrorHandler::noPermissions(); |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Set sessions based on the given headers in the request. |
|
259 | - * |
|
260 | - * @return void |
|
261 | - */ |
|
262 | - private function setSessions() |
|
263 | - { |
|
264 | - \Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
257 | + /** |
|
258 | + * Set sessions based on the given headers in the request. |
|
259 | + * |
|
260 | + * @return void |
|
261 | + */ |
|
262 | + private function setSessions() |
|
263 | + { |
|
264 | + \Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
265 | 265 | |
266 | - $locale = \Request::header('locale'); |
|
267 | - switch ($locale) |
|
268 | - { |
|
269 | - case 'en': |
|
270 | - \App::setLocale('en'); |
|
271 | - \Session::put('locale', 'en'); |
|
272 | - break; |
|
266 | + $locale = \Request::header('locale'); |
|
267 | + switch ($locale) |
|
268 | + { |
|
269 | + case 'en': |
|
270 | + \App::setLocale('en'); |
|
271 | + \Session::put('locale', 'en'); |
|
272 | + break; |
|
273 | 273 | |
274 | - case 'ar': |
|
275 | - \App::setLocale('ar'); |
|
276 | - \Session::put('locale', 'ar'); |
|
277 | - break; |
|
274 | + case 'ar': |
|
275 | + \App::setLocale('ar'); |
|
276 | + \Session::put('locale', 'ar'); |
|
277 | + break; |
|
278 | 278 | |
279 | - case 'all': |
|
280 | - \App::setLocale('en'); |
|
281 | - \Session::put('locale', 'all'); |
|
282 | - break; |
|
279 | + case 'all': |
|
280 | + \App::setLocale('en'); |
|
281 | + \Session::put('locale', 'all'); |
|
282 | + break; |
|
283 | 283 | |
284 | - default: |
|
285 | - \App::setLocale('en'); |
|
286 | - \Session::put('locale', 'en'); |
|
287 | - break; |
|
288 | - } |
|
289 | - } |
|
284 | + default: |
|
285 | + \App::setLocale('en'); |
|
286 | + \Session::put('locale', 'en'); |
|
287 | + break; |
|
288 | + } |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Set relation based on the called api. |
|
293 | - * |
|
294 | - * @param string $route |
|
295 | - * @return void |
|
296 | - */ |
|
297 | - private function setRelations($route) |
|
298 | - { |
|
299 | - $route = $route !== 'index' ? $route : 'list'; |
|
300 | - $relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
301 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
302 | - } |
|
291 | + /** |
|
292 | + * Set relation based on the called api. |
|
293 | + * |
|
294 | + * @param string $route |
|
295 | + * @return void |
|
296 | + */ |
|
297 | + private function setRelations($route) |
|
298 | + { |
|
299 | + $route = $route !== 'index' ? $route : 'list'; |
|
300 | + $relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
301 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
302 | + } |
|
303 | 303 | } |