We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -161,7 +161,7 @@ |
||
161 | 161 | * Remove the specified resource from storage. |
162 | 162 | * |
163 | 163 | * @param int $id |
164 | - * @return string |
|
164 | + * @return \Illuminate\Http\Response |
|
165 | 165 | */ |
166 | 166 | public function destroy($id) |
167 | 167 | { |
@@ -3,16 +3,12 @@ |
||
3 | 3 | use Illuminate\Foundation\Bus\DispatchesJobs; |
4 | 4 | use Illuminate\Routing\Controller as BaseController; |
5 | 5 | use Illuminate\Foundation\Validation\ValidatesRequests; |
6 | -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
|
7 | -use Illuminate\Support\Facades\Form as Form; |
|
8 | 6 | use Illuminate\Http\Request; |
9 | 7 | use Backpack\CRUD\Crud; |
10 | -use Crypt; |
|
11 | 8 | use Alert; |
12 | 9 | |
13 | 10 | |
14 | 11 | // VALIDATION: change the requests to match your own file names if you need form validation |
15 | -use Backpack\CRUD\app\Http\Requests\CrudRequest as StoreRequest; |
|
16 | 12 | use Backpack\CRUD\app\Http\Requests\CrudRequest as UpdateRequest; |
17 | 13 | |
18 | 14 | class CrudController extends BaseController { |
@@ -17,232 +17,232 @@ |
||
17 | 17 | |
18 | 18 | class CrudController extends BaseController { |
19 | 19 | |
20 | - use DispatchesJobs, ValidatesRequests; |
|
21 | - |
|
22 | - public $data = []; |
|
23 | - public $crud; |
|
24 | - |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->crud = new Crud(); |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Display all rows in the database for this entity. |
|
32 | - * |
|
33 | - * @return Response |
|
34 | - */ |
|
35 | - public function index() |
|
36 | - { |
|
37 | - $this->crud->hasAccessOrFail('list'); |
|
38 | - |
|
39 | - $this->data['entries'] = $this->crud->getEntries(); |
|
40 | - $this->data['crud'] = $this->crud; |
|
41 | - $this->data['title'] = ucfirst($this->crud->entity_name_plural); |
|
42 | - |
|
43 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
44 | - return view('crud::list', $this->data); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Show the form for creating inserting a new row. |
|
50 | - * |
|
51 | - * @return Response |
|
52 | - */ |
|
53 | - public function create() |
|
54 | - { |
|
55 | - $this->crud->hasAccessOrFail('create'); |
|
56 | - |
|
57 | - // prepare the fields you need to show |
|
58 | - $this->data['crud'] = $this->crud; |
|
59 | - $this->data['fields'] = $this->crud->getCreateFields(); |
|
60 | - $this->data['title'] = trans('backpack::crud.add').' '.$this->crud->entity_name; |
|
61 | - |
|
62 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
63 | - return view('crud::create', $this->data); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Store a newly created resource in the database. |
|
69 | - * |
|
70 | - * @param StoreRequest $request - type injection used for validation using Requests |
|
71 | - * @return \Illuminate\Http\RedirectResponse |
|
72 | - */ |
|
73 | - public function storeCrud(StoreRequest $request = null) |
|
74 | - { |
|
75 | - $this->crud->hasAccessOrFail('create'); |
|
20 | + use DispatchesJobs, ValidatesRequests; |
|
21 | + |
|
22 | + public $data = []; |
|
23 | + public $crud; |
|
24 | + |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->crud = new Crud(); |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Display all rows in the database for this entity. |
|
32 | + * |
|
33 | + * @return Response |
|
34 | + */ |
|
35 | + public function index() |
|
36 | + { |
|
37 | + $this->crud->hasAccessOrFail('list'); |
|
38 | + |
|
39 | + $this->data['entries'] = $this->crud->getEntries(); |
|
40 | + $this->data['crud'] = $this->crud; |
|
41 | + $this->data['title'] = ucfirst($this->crud->entity_name_plural); |
|
42 | + |
|
43 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
44 | + return view('crud::list', $this->data); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Show the form for creating inserting a new row. |
|
50 | + * |
|
51 | + * @return Response |
|
52 | + */ |
|
53 | + public function create() |
|
54 | + { |
|
55 | + $this->crud->hasAccessOrFail('create'); |
|
56 | + |
|
57 | + // prepare the fields you need to show |
|
58 | + $this->data['crud'] = $this->crud; |
|
59 | + $this->data['fields'] = $this->crud->getCreateFields(); |
|
60 | + $this->data['title'] = trans('backpack::crud.add').' '.$this->crud->entity_name; |
|
61 | + |
|
62 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
63 | + return view('crud::create', $this->data); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Store a newly created resource in the database. |
|
69 | + * |
|
70 | + * @param StoreRequest $request - type injection used for validation using Requests |
|
71 | + * @return \Illuminate\Http\RedirectResponse |
|
72 | + */ |
|
73 | + public function storeCrud(StoreRequest $request = null) |
|
74 | + { |
|
75 | + $this->crud->hasAccessOrFail('create'); |
|
76 | 76 | |
77 | 77 | |
78 | - // insert item in the db |
|
79 | - $item = $this->crud->create(\Request::except(['redirect_after_save', 'password'])); |
|
80 | - |
|
81 | - |
|
82 | - // show a success message |
|
83 | - \Alert::success(trans('backpack::crud.insert_success'))->flash(); |
|
84 | - |
|
85 | - // redirect the user where he chose to be redirected |
|
86 | - switch (\Request::input('redirect_after_save')) { |
|
87 | - case 'current_item_edit': |
|
88 | - return \Redirect::to($this->crud->route.'/'.$item->id.'/edit'); |
|
89 | - |
|
90 | - default: |
|
91 | - return \Redirect::to(\Request::input('redirect_after_save')); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Show the form for editing the specified resource. |
|
98 | - * |
|
99 | - * @param int $id |
|
100 | - * @return Response |
|
101 | - */ |
|
102 | - public function edit($id) |
|
103 | - { |
|
104 | - $this->crud->hasAccessOrFail('update'); |
|
105 | - |
|
106 | - // get the info for that entry |
|
107 | - $this->data['entry'] = $this->crud->getEntry($id); |
|
108 | - $this->data['crud'] = $this->crud; |
|
109 | - $this->data['fields'] = $this->crud->getUpdateFields($id); |
|
110 | - $this->data['title'] = trans('backpack::crud.edit').' '.$this->crud->entity_name; |
|
111 | - |
|
112 | - $this->data['id'] = $id; |
|
113 | - |
|
114 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
115 | - return view('crud::edit', $this->data); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Update the specified resource in the database. |
|
121 | - * |
|
122 | - * @param UpdateRequest $request - type injection used for validation using Requests |
|
123 | - * @return \Illuminate\Http\RedirectResponse |
|
124 | - */ |
|
125 | - public function updateCrud(UpdateRequest $request = null) |
|
126 | - { |
|
127 | - $this->crud->hasAccessOrFail('update'); |
|
128 | - |
|
129 | - // update the row in the db |
|
130 | - |
|
131 | - $this->crud->update(\Request::get('id'), \Request::except('redirect_after_save')); |
|
132 | - |
|
133 | - // show a success message |
|
134 | - \Alert::success(trans('backpack::crud.update_success'))->flash(); |
|
135 | - |
|
136 | - return \Redirect::to($this->crud->route); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Display the specified resource. |
|
142 | - * |
|
143 | - * @param int $id |
|
144 | - * @return Response |
|
145 | - */ |
|
146 | - public function show($id) |
|
147 | - { |
|
148 | - $this->crud->hasAccessOrFail('show'); |
|
149 | - |
|
150 | - // get the info for that entry |
|
151 | - $this->data['entry'] = $this->crud->getEntry($id); |
|
152 | - $this->data['crud'] = $this->crud; |
|
153 | - $this->data['title'] = trans('backpack::crud.preview').' '.$this->crud->entity_name; |
|
154 | - |
|
155 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
156 | - return view('crud::show', $this->data); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Remove the specified resource from storage. |
|
162 | - * |
|
163 | - * @param int $id |
|
164 | - * @return string |
|
165 | - */ |
|
166 | - public function destroy($id) |
|
167 | - { |
|
168 | - $this->crud->hasAccessOrFail('delete'); |
|
169 | - return $this->crud->delete($id); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Reorder the items in the database using the Nested Set pattern. |
|
175 | - * |
|
176 | - * Database columns needed: id, parent_id, lft, rgt, depth, name/title |
|
177 | - * |
|
178 | - * @return Response |
|
179 | - */ |
|
180 | - public function reorder($lang = false) |
|
181 | - { |
|
182 | - $this->crud->hasAccessOrFail('reorder'); |
|
183 | - |
|
184 | - if (!$this->crud->isReorderEnabled()) { |
|
185 | - abort(403, 'Reorder is disabled.'); |
|
186 | - } |
|
187 | - |
|
188 | - if ($lang == false) |
|
189 | - { |
|
190 | - $lang = \Lang::locale(); |
|
191 | - } |
|
192 | - |
|
193 | - // get all results for that entity |
|
194 | - $this->data['entries'] = $this->crud->getEntries(); |
|
195 | - $this->data['crud'] = $this->crud; |
|
196 | - $this->data['title'] = trans('backpack::crud.reorder').' '.$this->crud->entity_name; |
|
197 | - |
|
198 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
199 | - return view('crud::reorder', $this->data); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Save the new order, using the Nested Set pattern. |
|
205 | - * |
|
206 | - * Database columns needed: id, parent_id, lft, rgt, depth, name/title |
|
207 | - * |
|
208 | - * @return |
|
209 | - */ |
|
210 | - public function saveReorder() |
|
211 | - { |
|
212 | - $this->crud->hasAccessOrFail('reorder'); |
|
213 | - |
|
214 | - $all_entries = \Request::input('tree'); |
|
215 | - |
|
216 | - if (count($all_entries)) { |
|
217 | - $count = $this->crud->updateTreeOrder($all_entries); |
|
218 | - } else |
|
219 | - { |
|
220 | - return false; |
|
221 | - } |
|
222 | - |
|
223 | - return 'success for '.$count." items"; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table. |
|
229 | - * It defaults to showing some dummy text. |
|
230 | - * |
|
231 | - * It's enabled by: |
|
232 | - * - setting: $crud->details_row = true; |
|
233 | - * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow'); |
|
234 | - * - adding a view with the following name to change what the row actually contains: app/resources/views/vendor/backpack/crud/details_row.blade.php |
|
235 | - */ |
|
236 | - public function showDetailsRow($id) |
|
237 | - { |
|
238 | - $this->crud->hasAccessOrFail('details_row'); |
|
239 | - |
|
240 | - $this->data['entry'] = $this->crud->getEntry($id); |
|
241 | - $this->data['crud'] = $this->crud; |
|
242 | - |
|
243 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
244 | - return view('crud::details_row', $this->data); |
|
245 | - } |
|
78 | + // insert item in the db |
|
79 | + $item = $this->crud->create(\Request::except(['redirect_after_save', 'password'])); |
|
80 | + |
|
81 | + |
|
82 | + // show a success message |
|
83 | + \Alert::success(trans('backpack::crud.insert_success'))->flash(); |
|
84 | + |
|
85 | + // redirect the user where he chose to be redirected |
|
86 | + switch (\Request::input('redirect_after_save')) { |
|
87 | + case 'current_item_edit': |
|
88 | + return \Redirect::to($this->crud->route.'/'.$item->id.'/edit'); |
|
89 | + |
|
90 | + default: |
|
91 | + return \Redirect::to(\Request::input('redirect_after_save')); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Show the form for editing the specified resource. |
|
98 | + * |
|
99 | + * @param int $id |
|
100 | + * @return Response |
|
101 | + */ |
|
102 | + public function edit($id) |
|
103 | + { |
|
104 | + $this->crud->hasAccessOrFail('update'); |
|
105 | + |
|
106 | + // get the info for that entry |
|
107 | + $this->data['entry'] = $this->crud->getEntry($id); |
|
108 | + $this->data['crud'] = $this->crud; |
|
109 | + $this->data['fields'] = $this->crud->getUpdateFields($id); |
|
110 | + $this->data['title'] = trans('backpack::crud.edit').' '.$this->crud->entity_name; |
|
111 | + |
|
112 | + $this->data['id'] = $id; |
|
113 | + |
|
114 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
115 | + return view('crud::edit', $this->data); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Update the specified resource in the database. |
|
121 | + * |
|
122 | + * @param UpdateRequest $request - type injection used for validation using Requests |
|
123 | + * @return \Illuminate\Http\RedirectResponse |
|
124 | + */ |
|
125 | + public function updateCrud(UpdateRequest $request = null) |
|
126 | + { |
|
127 | + $this->crud->hasAccessOrFail('update'); |
|
128 | + |
|
129 | + // update the row in the db |
|
130 | + |
|
131 | + $this->crud->update(\Request::get('id'), \Request::except('redirect_after_save')); |
|
132 | + |
|
133 | + // show a success message |
|
134 | + \Alert::success(trans('backpack::crud.update_success'))->flash(); |
|
135 | + |
|
136 | + return \Redirect::to($this->crud->route); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Display the specified resource. |
|
142 | + * |
|
143 | + * @param int $id |
|
144 | + * @return Response |
|
145 | + */ |
|
146 | + public function show($id) |
|
147 | + { |
|
148 | + $this->crud->hasAccessOrFail('show'); |
|
149 | + |
|
150 | + // get the info for that entry |
|
151 | + $this->data['entry'] = $this->crud->getEntry($id); |
|
152 | + $this->data['crud'] = $this->crud; |
|
153 | + $this->data['title'] = trans('backpack::crud.preview').' '.$this->crud->entity_name; |
|
154 | + |
|
155 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
156 | + return view('crud::show', $this->data); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Remove the specified resource from storage. |
|
162 | + * |
|
163 | + * @param int $id |
|
164 | + * @return string |
|
165 | + */ |
|
166 | + public function destroy($id) |
|
167 | + { |
|
168 | + $this->crud->hasAccessOrFail('delete'); |
|
169 | + return $this->crud->delete($id); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Reorder the items in the database using the Nested Set pattern. |
|
175 | + * |
|
176 | + * Database columns needed: id, parent_id, lft, rgt, depth, name/title |
|
177 | + * |
|
178 | + * @return Response |
|
179 | + */ |
|
180 | + public function reorder($lang = false) |
|
181 | + { |
|
182 | + $this->crud->hasAccessOrFail('reorder'); |
|
183 | + |
|
184 | + if (!$this->crud->isReorderEnabled()) { |
|
185 | + abort(403, 'Reorder is disabled.'); |
|
186 | + } |
|
187 | + |
|
188 | + if ($lang == false) |
|
189 | + { |
|
190 | + $lang = \Lang::locale(); |
|
191 | + } |
|
192 | + |
|
193 | + // get all results for that entity |
|
194 | + $this->data['entries'] = $this->crud->getEntries(); |
|
195 | + $this->data['crud'] = $this->crud; |
|
196 | + $this->data['title'] = trans('backpack::crud.reorder').' '.$this->crud->entity_name; |
|
197 | + |
|
198 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
199 | + return view('crud::reorder', $this->data); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Save the new order, using the Nested Set pattern. |
|
205 | + * |
|
206 | + * Database columns needed: id, parent_id, lft, rgt, depth, name/title |
|
207 | + * |
|
208 | + * @return |
|
209 | + */ |
|
210 | + public function saveReorder() |
|
211 | + { |
|
212 | + $this->crud->hasAccessOrFail('reorder'); |
|
213 | + |
|
214 | + $all_entries = \Request::input('tree'); |
|
215 | + |
|
216 | + if (count($all_entries)) { |
|
217 | + $count = $this->crud->updateTreeOrder($all_entries); |
|
218 | + } else |
|
219 | + { |
|
220 | + return false; |
|
221 | + } |
|
222 | + |
|
223 | + return 'success for '.$count." items"; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table. |
|
229 | + * It defaults to showing some dummy text. |
|
230 | + * |
|
231 | + * It's enabled by: |
|
232 | + * - setting: $crud->details_row = true; |
|
233 | + * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow'); |
|
234 | + * - adding a view with the following name to change what the row actually contains: app/resources/views/vendor/backpack/crud/details_row.blade.php |
|
235 | + */ |
|
236 | + public function showDetailsRow($id) |
|
237 | + { |
|
238 | + $this->crud->hasAccessOrFail('details_row'); |
|
239 | + |
|
240 | + $this->data['entry'] = $this->crud->getEntry($id); |
|
241 | + $this->data['crud'] = $this->crud; |
|
242 | + |
|
243 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
244 | + return view('crud::details_row', $this->data); |
|
245 | + } |
|
246 | 246 | |
247 | 247 | |
248 | 248 |
@@ -1,12 +1,8 @@ |
||
1 | 1 | <?php namespace App\Http\Controllers\Admin; |
2 | 2 | |
3 | -use App\Http\Requests; |
|
4 | -use App\Http\Controllers\Controller; |
|
5 | 3 | use Backpack\CRUD\app\Http\Controllers\CrudController; |
6 | -use Illuminate\Http\Request; |
|
7 | 4 | |
8 | 5 | // VALIDATION: change the requests to match your own file names if you need form validation |
9 | -use Backpack\CRUD\app\Http\Requests\CrudRequest as StoreRequest; |
|
10 | 6 | use Backpack\CRUD\app\Http\Requests\CrudRequest as UpdateRequest; |
11 | 7 | |
12 | 8 | class ExampleCrudController extends CrudController { |
@@ -11,17 +11,17 @@ discard block |
||
11 | 11 | |
12 | 12 | class ExampleCrudController extends CrudController { |
13 | 13 | |
14 | - public function __construct() { |
|
14 | + public function __construct() { |
|
15 | 15 | parent::__construct(); |
16 | 16 | |
17 | - /* |
|
17 | + /* |
|
18 | 18 | |-------------------------------------------------------------------------- |
19 | 19 | | API |
20 | 20 | |-------------------------------------------------------------------------- |
21 | 21 | */ |
22 | 22 | |
23 | 23 | |
24 | - // USAGE LEVEL 1 - ALWAYS ================================================== LEVEL 1 |
|
24 | + // USAGE LEVEL 1 - ALWAYS ================================================== LEVEL 1 |
|
25 | 25 | $this->crud->setModel("App\Models\Example"); |
26 | 26 | $this->crud->setRoute("admin/example"); |
27 | 27 | // $this->crud->setRouteName("admin.example"); |
@@ -33,45 +33,45 @@ discard block |
||
33 | 33 | |
34 | 34 | |
35 | 35 | |
36 | - // USAGE LEVEL 2 - OFTEN ================================================== LEVEL 2 |
|
36 | + // USAGE LEVEL 2 - OFTEN ================================================== LEVEL 2 |
|
37 | 37 | |
38 | 38 | |
39 | 39 | // ------ FIELDS (the last parameter is always the form - create/update/both) |
40 | - // TODO: $this->crud->addField('name', $options, 'update/create/both'); |
|
41 | - // TODO: $this->crud->addFields($array_of_arrays, 'update/create/both'); |
|
42 | - // TODO: $this->crud->removeField('name', 'update/create/both'); |
|
43 | - // TODO: $this->crud->removeFields($array_of_names, 'update/create/both'); |
|
44 | - // TODO: $this->crud->replaceField('name', 'update/create/both'); |
|
40 | + // TODO: $this->crud->addField('name', $options, 'update/create/both'); |
|
41 | + // TODO: $this->crud->addFields($array_of_arrays, 'update/create/both'); |
|
42 | + // TODO: $this->crud->removeField('name', 'update/create/both'); |
|
43 | + // TODO: $this->crud->removeFields($array_of_names, 'update/create/both'); |
|
44 | + // TODO: $this->crud->replaceField('name', 'update/create/both'); |
|
45 | 45 | |
46 | - // TODO: $this->crud->setRequiredFields(['field_1', 'field_2'], 'update/create/both'); |
|
47 | - // TODO: $this->crud->setRequiredField('field_1', 'update/create/both'); |
|
48 | - // TODO: $this->crud->getRequiredFields(); |
|
46 | + // TODO: $this->crud->setRequiredFields(['field_1', 'field_2'], 'update/create/both'); |
|
47 | + // TODO: $this->crud->setRequiredField('field_1', 'update/create/both'); |
|
48 | + // TODO: $this->crud->getRequiredFields(); |
|
49 | 49 | |
50 | - // TODO: $this->crud->setFieldOrder(['field_1', 'field_2', 'field_3'], 'update/create/both'); |
|
50 | + // TODO: $this->crud->setFieldOrder(['field_1', 'field_2', 'field_3'], 'update/create/both'); |
|
51 | 51 | |
52 | 52 | |
53 | 53 | // ------ COLUMNS |
54 | - // $this->crud->addColumn(); // add a single column, at the end of the stack |
|
55 | - // $this->crud->addColumns(); // add multiple columns, at the end of the stack |
|
56 | - // $this->crud->removeColumn('column_name'); // remove a column from the stack |
|
57 | - // $this->crud->removeColumns(['column_name_1', 'column_name_2']); // remove an array of columns from the stack |
|
58 | - // $this->crud->setColumnDetails('column_name', ['attribute' => 'value']); |
|
59 | - // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']); |
|
60 | - // TODO: $this->crud->setColumnOrder(['column_1', 'column_2', 'column_3']); |
|
54 | + // $this->crud->addColumn(); // add a single column, at the end of the stack |
|
55 | + // $this->crud->addColumns(); // add multiple columns, at the end of the stack |
|
56 | + // $this->crud->removeColumn('column_name'); // remove a column from the stack |
|
57 | + // $this->crud->removeColumns(['column_name_1', 'column_name_2']); // remove an array of columns from the stack |
|
58 | + // $this->crud->setColumnDetails('column_name', ['attribute' => 'value']); |
|
59 | + // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']); |
|
60 | + // TODO: $this->crud->setColumnOrder(['column_1', 'column_2', 'column_3']); |
|
61 | 61 | |
62 | 62 | |
63 | - // ------ FIELDS AND COLUMNS |
|
64 | - // TODO: $this->crud->setLabel('column_name/field_name', 'New Label'); // changes label for columns, create&update fields |
|
63 | + // ------ FIELDS AND COLUMNS |
|
64 | + // TODO: $this->crud->setLabel('column_name/field_name', 'New Label'); // changes label for columns, create&update fields |
|
65 | 65 | |
66 | 66 | |
67 | 67 | // ------ ACCESS |
68 | - // $this->crud->allowAccess('list'); |
|
69 | - // $this->crud->allowAccess(['list', 'create', 'delete']); |
|
70 | - // $this->crud->denyAccess('list'); |
|
71 | - // $this->crud->denyAccess(['list', 'create', 'delete']); |
|
68 | + // $this->crud->allowAccess('list'); |
|
69 | + // $this->crud->allowAccess(['list', 'create', 'delete']); |
|
70 | + // $this->crud->denyAccess('list'); |
|
71 | + // $this->crud->denyAccess(['list', 'create', 'delete']); |
|
72 | 72 | |
73 | - // $this->crud->hasAccess('add'); // returns true/false |
|
74 | - // $this->crud->hasAccessOrFail('add'); // throws 403 error |
|
73 | + // $this->crud->hasAccess('add'); // returns true/false |
|
74 | + // $this->crud->hasAccessOrFail('add'); // throws 403 error |
|
75 | 75 | |
76 | 76 | |
77 | 77 | // ------ REORDER |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | |
85 | 85 | // ------ DETAILS ROW |
86 | - // $this->crud->enableDetailsRow(); |
|
86 | + // $this->crud->enableDetailsRow(); |
|
87 | 87 | // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('details_row'); |
88 | 88 | // NOTE: you also need to do overwrite the showDetailsRow($id) method in your EntityCrudController to show whatever you'd like in the details row OR overwrite the views/backpack/crud/details_row.blade.php |
89 | 89 | |
@@ -92,101 +92,101 @@ discard block |
||
92 | 92 | |
93 | 93 | // ------ ADVANCED QUERIES |
94 | 94 | // $this->crud->addClause('active'); |
95 | - // $this->crud->addClause('type', 'car'); |
|
96 | - // $this->crud->addClause('where', 'name', '==', 'car'); |
|
97 | - // $this->crud->addClause('whereName', 'car'); |
|
98 | - // $this->crud->addClause('whereHas', 'posts', function($query) { |
|
99 | - // $query->activePosts(); |
|
100 | - // }); |
|
95 | + // $this->crud->addClause('type', 'car'); |
|
96 | + // $this->crud->addClause('where', 'name', '==', 'car'); |
|
97 | + // $this->crud->addClause('whereName', 'car'); |
|
98 | + // $this->crud->addClause('whereHas', 'posts', function($query) { |
|
99 | + // $query->activePosts(); |
|
100 | + // }); |
|
101 | 101 | // $this->crud->orderBy(); |
102 | 102 | // $this->crud->groupBy(); |
103 | 103 | // $this->crud->limit(); |
104 | 104 | |
105 | 105 | |
106 | 106 | |
107 | - // USAGE LEVEL 3 - SOMETIMES ============================================== LEVEL 3 |
|
107 | + // USAGE LEVEL 3 - SOMETIMES ============================================== LEVEL 3 |
|
108 | 108 | |
109 | 109 | // TODO: $this->crud->setButtons(); // default includes edit and delete, with their name, icon, permission, link and class (btn-default) |
110 | - // TODO: $this->crud->addButton(); |
|
111 | - // TODO: $this->crud->removeButton(); |
|
112 | - // TODO: $this->crud->replaceButton(); |
|
110 | + // TODO: $this->crud->addButton(); |
|
111 | + // TODO: $this->crud->removeButton(); |
|
112 | + // TODO: $this->crud->replaceButton(); |
|
113 | 113 | |
114 | 114 | |
115 | 115 | |
116 | - // USAGE LEVEL 4 - RARELY ================================================== LEVEL 4 |
|
116 | + // USAGE LEVEL 4 - RARELY ================================================== LEVEL 4 |
|
117 | 117 | |
118 | - // $this->crud->getEntry($entry_id); |
|
119 | - // $this->crud->getEntries(); |
|
118 | + // $this->crud->getEntry($entry_id); |
|
119 | + // $this->crud->getEntries(); |
|
120 | 120 | |
121 | - // $this->crud->getFields('create/update/both'); |
|
121 | + // $this->crud->getFields('create/update/both'); |
|
122 | 122 | |
123 | - // $this->crud->create($entry_request); |
|
124 | - // $this->crud->update($entry_id, $entry_request); |
|
125 | - // $this->crud->delete($entry_id); |
|
123 | + // $this->crud->create($entry_request); |
|
124 | + // $this->crud->update($entry_id, $entry_request); |
|
125 | + // $this->crud->delete($entry_id); |
|
126 | 126 | |
127 | 127 | |
128 | - // USAGE LEVEL 5 - ALMOST NEVER ============================================== LEVEL 5 |
|
128 | + // USAGE LEVEL 5 - ALMOST NEVER ============================================== LEVEL 5 |
|
129 | 129 | |
130 | - // $this->crud->updateTreeOrder($all_entries); |
|
130 | + // $this->crud->updateTreeOrder($all_entries); |
|
131 | 131 | |
132 | 132 | |
133 | 133 | |
134 | 134 | |
135 | 135 | // ------------------------ |
136 | - // MEANWHILE THIS WILL WORK |
|
137 | - // ------------------------ |
|
136 | + // MEANWHILE THIS WILL WORK |
|
137 | + // ------------------------ |
|
138 | 138 | |
139 | 139 | |
140 | 140 | $this->crud->reorder = true; |
141 | - $this->crud->reorder_label = "name"; |
|
142 | - $this->crud->reorder_max_level = 3; |
|
143 | - $this->crud->details_row = true; |
|
144 | - // $this->crud->permissions = ['add', 'list', 'edit', 'delete', 'show']; |
|
141 | + $this->crud->reorder_label = "name"; |
|
142 | + $this->crud->reorder_max_level = 3; |
|
143 | + $this->crud->details_row = true; |
|
144 | + // $this->crud->permissions = ['add', 'list', 'edit', 'delete', 'show']; |
|
145 | 145 | |
146 | 146 | $this->crud->columns = [ |
147 | - [ |
|
148 | - 'name' => 'name', |
|
149 | - 'label' => "Example item text" |
|
150 | - ], |
|
151 | - [ |
|
152 | - 'label' => "Parent", |
|
153 | - 'type' => 'select', |
|
154 | - 'name' => 'parent_id', |
|
155 | - 'entity' => 'parent', |
|
156 | - 'attribute' => 'name', |
|
157 | - 'model' => "App\Models\Example" |
|
158 | - ], |
|
159 | - ]; |
|
160 | - $this->crud->fields = [ |
|
161 | - [ |
|
162 | - 'name' => 'name', |
|
163 | - 'label' => "Example item text" |
|
164 | - ], |
|
165 | - [ |
|
166 | - 'label' => "Parent", |
|
167 | - 'type' => 'select', |
|
168 | - 'name' => 'parent_id', |
|
169 | - 'entity' => 'parent', |
|
170 | - 'attribute' => 'name', |
|
171 | - 'model' => "App\Models\Example" |
|
172 | - ], |
|
173 | - [ |
|
174 | - 'name' => 'type', |
|
175 | - 'label' => "Type", |
|
176 | - 'type' => 'page_or_link' |
|
177 | - ], |
|
178 | - ]; |
|
147 | + [ |
|
148 | + 'name' => 'name', |
|
149 | + 'label' => "Example item text" |
|
150 | + ], |
|
151 | + [ |
|
152 | + 'label' => "Parent", |
|
153 | + 'type' => 'select', |
|
154 | + 'name' => 'parent_id', |
|
155 | + 'entity' => 'parent', |
|
156 | + 'attribute' => 'name', |
|
157 | + 'model' => "App\Models\Example" |
|
158 | + ], |
|
159 | + ]; |
|
160 | + $this->crud->fields = [ |
|
161 | + [ |
|
162 | + 'name' => 'name', |
|
163 | + 'label' => "Example item text" |
|
164 | + ], |
|
165 | + [ |
|
166 | + 'label' => "Parent", |
|
167 | + 'type' => 'select', |
|
168 | + 'name' => 'parent_id', |
|
169 | + 'entity' => 'parent', |
|
170 | + 'attribute' => 'name', |
|
171 | + 'model' => "App\Models\Example" |
|
172 | + ], |
|
173 | + [ |
|
174 | + 'name' => 'type', |
|
175 | + 'label' => "Type", |
|
176 | + 'type' => 'page_or_link' |
|
177 | + ], |
|
178 | + ]; |
|
179 | 179 | |
180 | 180 | } |
181 | 181 | |
182 | - public function store(StoreRequest $request) |
|
183 | - { |
|
184 | - return parent::storeCrud(); |
|
185 | - } |
|
182 | + public function store(StoreRequest $request) |
|
183 | + { |
|
184 | + return parent::storeCrud(); |
|
185 | + } |
|
186 | 186 | |
187 | - public function update(UpdateRequest $request) |
|
188 | - { |
|
189 | - return parent::updateCrud(); |
|
190 | - } |
|
187 | + public function update(UpdateRequest $request) |
|
188 | + { |
|
189 | + return parent::updateCrud(); |
|
190 | + } |
|
191 | 191 | |
192 | 192 | } |
@@ -157,7 +157,7 @@ |
||
157 | 157 | 'model' => "App\Models\Example" |
158 | 158 | ], |
159 | 159 | ]; |
160 | - $this->crud->fields = [ |
|
160 | + $this->crud->fields = [ |
|
161 | 161 | [ |
162 | 162 | 'name' => 'name', |
163 | 163 | 'label' => "Example item text" |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * Store a newly created resource in storage. |
55 | 55 | * |
56 | 56 | * @param \Illuminate\Http\Request $request |
57 | - * @return \Illuminate\Http\Response |
|
57 | + * @return \Illuminate\Http\RedirectResponse |
|
58 | 58 | */ |
59 | 59 | public function crudStore(Request $request = null) |
60 | 60 | { |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @param \Illuminate\Http\Request $request |
103 | 103 | * @param int $id |
104 | - * @return \Illuminate\Http\Response |
|
104 | + * @return \Illuminate\Http\RedirectResponse |
|
105 | 105 | */ |
106 | 106 | public function crudUpdate($parentId, $id, Request $request = null) |
107 | 107 | { |
@@ -4,10 +4,7 @@ |
||
4 | 4 | */ |
5 | 5 | namespace Backpack\Crud\Http\Controllers; |
6 | 6 | |
7 | -use Illuminate\Foundation\Bus\DispatchesJobs; |
|
8 | 7 | use Illuminate\Routing\Controller as BaseController; |
9 | -use Illuminate\Foundation\Validation\ValidatesRequests; |
|
10 | -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
|
11 | 8 | use Backpack\Crud\Crud; |
12 | 9 | |
13 | 10 | /** |
@@ -286,6 +286,7 @@ discard block |
||
286 | 286 | * Delete a row from the database. |
287 | 287 | * |
288 | 288 | * @param [int] The id of the item to be deleted. |
289 | + * @param integer $id |
|
289 | 290 | * @return [bool] Deletion confirmation. |
290 | 291 | * |
291 | 292 | * TODO: should this delete items with relations to it too? |
@@ -404,7 +405,8 @@ discard block |
||
404 | 405 | * Check if a permission is enabled for a Crud Panel. Fail if not. |
405 | 406 | * |
406 | 407 | * @param [string] Permission. |
407 | - * @return boolean |
|
408 | + * @param string $permission |
|
409 | + * @return boolean|null |
|
408 | 410 | */ |
409 | 411 | public function hasAccessOrFail($permission) |
410 | 412 | { |
@@ -433,6 +435,7 @@ discard block |
||
433 | 435 | * All Create-Read-Update-Delete operations are done using that Eloquent Collection. |
434 | 436 | * |
435 | 437 | * @param [string] Full model namespace. Ex: App\Models\Article |
438 | + * @param string $model_namespace |
|
436 | 439 | */ |
437 | 440 | public function setModel($model_namespace) |
438 | 441 | { |
@@ -460,6 +463,7 @@ discard block |
||
460 | 463 | * |
461 | 464 | * @param [string] Route name. |
462 | 465 | * @param [array] Parameters. |
466 | + * @param string $route |
|
463 | 467 | */ |
464 | 468 | public function setRoute($route) |
465 | 469 | { |
@@ -492,7 +496,7 @@ discard block |
||
492 | 496 | * - $this->crud->setRouteName('admin.article') |
493 | 497 | * - $this->crud->route = "admin/article" |
494 | 498 | * |
495 | - * @return [string] |
|
499 | + * @return string |
|
496 | 500 | */ |
497 | 501 | public function getRoute() |
498 | 502 | { |
@@ -505,6 +509,8 @@ discard block |
||
505 | 509 | * |
506 | 510 | * @param [string] Entity name, in singular. Ex: article |
507 | 511 | * @param [string] Entity name, in plural. Ex: articles |
512 | + * @param string $singular |
|
513 | + * @param string $plural |
|
508 | 514 | */ |
509 | 515 | public function setEntityNameStrings($singular, $plural) { |
510 | 516 | $this->entity_name = $singular; |
@@ -1237,6 +1243,9 @@ discard block |
||
1237 | 1243 | return array_filter($this->{$entity}[] = $this->syncField($field)); |
1238 | 1244 | } |
1239 | 1245 | |
1246 | + /** |
|
1247 | + * @param string $entity |
|
1248 | + */ |
|
1240 | 1249 | public function addMultiple($entity, $field) |
1241 | 1250 | { |
1242 | 1251 | $this->{$entity} = array_filter(array_map([$this, 'syncField'], $fields)); |
@@ -1256,16 +1265,25 @@ discard block |
||
1256 | 1265 | |
1257 | 1266 | |
1258 | 1267 | |
1268 | + /** |
|
1269 | + * @param string $entity |
|
1270 | + */ |
|
1259 | 1271 | public function remove($entity, $fields) |
1260 | 1272 | { |
1261 | 1273 | return array_values(array_filter($this->{$entity}, function($field) use ($fields) { return !in_array($field['name'], (array)$fields);})); |
1262 | 1274 | } |
1263 | 1275 | |
1276 | + /** |
|
1277 | + * @param string $items |
|
1278 | + */ |
|
1264 | 1279 | public function setSort($items, $order) |
1265 | 1280 | { |
1266 | 1281 | $this->sort[$items] = $order; |
1267 | 1282 | } |
1268 | 1283 | |
1284 | + /** |
|
1285 | + * @param string $items |
|
1286 | + */ |
|
1269 | 1287 | public function sort($items) |
1270 | 1288 | { |
1271 | 1289 | if (array_key_exists($items, $this->sort)) |
@@ -1301,6 +1319,10 @@ discard block |
||
1301 | 1319 | } |
1302 | 1320 | |
1303 | 1321 | // face un fel de merge intre ce ii dai si ce e in CRUD |
1322 | + |
|
1323 | + /** |
|
1324 | + * @param string $entity |
|
1325 | + */ |
|
1304 | 1326 | public function syncRelations($entity) |
1305 | 1327 | { |
1306 | 1328 | foreach ($this->relations as $field => $relation) { |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | if(isset($data[$relation])){ |
123 | 123 | $model->{$relation}()->sync($data[$relation]); |
124 | 124 | }else{ |
125 | - $model->{$relation}()->sync([]); |
|
125 | + $model->{$relation}()->sync([]); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | }else{ |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | |
132 | 132 | if( isset($relation['pivotFields']) ){ |
133 | 133 | foreach($relation['pivotFields'] as $pivotField){ |
134 | - foreach($data[$pivotField] as $pivot_id => $field){ |
|
135 | - $model->{$relation['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]); |
|
136 | - } |
|
134 | + foreach($data[$pivotField] as $pivot_id => $field){ |
|
135 | + $model->{$relation['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]); |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | |
178 | - /* |
|
178 | + /* |
|
179 | 179 | |-------------------------------------------------------------------------- |
180 | 180 | | READ |
181 | 181 | |-------------------------------------------------------------------------- |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | |
258 | 258 | |
259 | 259 | |
260 | - /* |
|
260 | + /* |
|
261 | 261 | |-------------------------------------------------------------------------- |
262 | 262 | | UPDATE |
263 | 263 | |-------------------------------------------------------------------------- |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | |
323 | 323 | |
324 | 324 | |
325 | - /* |
|
325 | + /* |
|
326 | 326 | |-------------------------------------------------------------------------- |
327 | 327 | | DELETE |
328 | 328 | |-------------------------------------------------------------------------- |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | |
414 | 414 | |
415 | 415 | |
416 | - /* |
|
416 | + /* |
|
417 | 417 | |-------------------------------------------------------------------------- |
418 | 418 | | CRUD ACCESS |
419 | 419 | |-------------------------------------------------------------------------- |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | |
843 | 843 | if (!in_array($field, $this->model->getHidden())) |
844 | 844 | { |
845 | - $this->columns[] = [ |
|
845 | + $this->columns[] = [ |
|
846 | 846 | 'name' => $field, |
847 | 847 | 'label' => ucfirst($field), |
848 | 848 | 'type' => $this->getFieldTypeFromDbColumnType($field) |
@@ -1210,10 +1210,10 @@ discard block |
||
1210 | 1210 | |
1211 | 1211 | public function addCreateField($field) |
1212 | 1212 | { |
1213 | - return $this->add('create_fields', $field); |
|
1213 | + return $this->add('create_fields', $field); |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | - public function setUpdateFields($fields) |
|
1216 | + public function setUpdateFields($fields) |
|
1217 | 1217 | { |
1218 | 1218 | $this->addMultiple('update_fields', $fields); |
1219 | 1219 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function getCreateFields() |
82 | 82 | { |
83 | - return $this->prepareFields(empty($this->create_fields)?$this->fields:$this->create_fields); |
|
83 | + return $this->prepareFields(empty($this->create_fields) ? $this->fields : $this->create_fields); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function getRelationFields($form = 'create') |
93 | 93 | { |
94 | - if( $form == 'create' ){ |
|
95 | - $fields = empty($this->create_fields)?$this->fields:$this->create_fields; |
|
96 | - }else{ |
|
97 | - $fields = empty($this->update_fields)?$this->fields:$this->update_fields; |
|
94 | + if ($form == 'create') { |
|
95 | + $fields = empty($this->create_fields) ? $this->fields : $this->create_fields; |
|
96 | + } else { |
|
97 | + $fields = empty($this->update_fields) ? $this->fields : $this->update_fields; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $relationFields = []; |
101 | 101 | |
102 | - foreach($fields as $field){ |
|
103 | - if(isset($field['model']) || isset($field['dependencies'])){ |
|
102 | + foreach ($fields as $field) { |
|
103 | + if (isset($field['model']) || isset($field['dependencies'])) { |
|
104 | 104 | array_push($relationFields, $field); |
105 | 105 | } |
106 | 106 | } |
@@ -116,22 +116,22 @@ discard block |
||
116 | 116 | |
117 | 117 | foreach ($relations as $key => $relation) |
118 | 118 | { |
119 | - if ( (isset($relation['pivot']) && $relation['pivot'] ) || isset($relation['dependencies']) ){ |
|
120 | - if(is_array($relation['name'])){ |
|
121 | - foreach($relation['name'] as $relation){ |
|
122 | - if(isset($data[$relation])){ |
|
119 | + if ((isset($relation['pivot']) && $relation['pivot']) || isset($relation['dependencies'])) { |
|
120 | + if (is_array($relation['name'])) { |
|
121 | + foreach ($relation['name'] as $relation) { |
|
122 | + if (isset($data[$relation])) { |
|
123 | 123 | $model->{$relation}()->sync($data[$relation]); |
124 | - }else{ |
|
124 | + } else { |
|
125 | 125 | $model->{$relation}()->sync([]); |
126 | 126 | } |
127 | 127 | } |
128 | - }else{ |
|
128 | + } else { |
|
129 | 129 | $model->{$relation['name']}()->sync($data[$relation['name']]); |
130 | 130 | } |
131 | 131 | |
132 | - if( isset($relation['pivotFields']) ){ |
|
133 | - foreach($relation['pivotFields'] as $pivotField){ |
|
134 | - foreach($data[$pivotField] as $pivot_id => $field){ |
|
132 | + if (isset($relation['pivotFields'])) { |
|
133 | + foreach ($relation['pivotFields'] as $pivotField) { |
|
134 | + foreach ($data[$pivotField] as $pivot_id => $field) { |
|
135 | 135 | $model->{$relation['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]); |
136 | 136 | } |
137 | 137 | } |
@@ -289,21 +289,21 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function getUpdateFields($id) |
291 | 291 | { |
292 | - $fields = $this->prepareFields(empty($this->update_fields)?$this->fields:$this->update_fields); |
|
292 | + $fields = $this->prepareFields(empty($this->update_fields) ? $this->fields : $this->update_fields); |
|
293 | 293 | $entry = $this->getEntry($id); |
294 | 294 | |
295 | 295 | foreach ($fields as $k => $field) { |
296 | 296 | // set the value |
297 | 297 | if (!isset($fields[$k]['value'])) |
298 | 298 | { |
299 | - if(is_array($field['name'])){ |
|
299 | + if (is_array($field['name'])) { |
|
300 | 300 | |
301 | 301 | $fields[$k]['value'] = []; |
302 | - foreach($field['name'] as $key => $relation){ |
|
302 | + foreach ($field['name'] as $key => $relation) { |
|
303 | 303 | $fields[$k]['value'][] = $entry->{$relation}; |
304 | 304 | } |
305 | 305 | |
306 | - }else{ |
|
306 | + } else { |
|
307 | 307 | $fields[$k]['value'] = $entry->{$field['name']}; |
308 | 308 | } |
309 | 309 | } |
@@ -422,13 +422,13 @@ discard block |
||
422 | 422 | public function allowAccess($access) |
423 | 423 | { |
424 | 424 | // $this->addButtons((array)$access); |
425 | - return $this->access = array_merge(array_diff((array)$access, $this->access), $this->access); |
|
425 | + return $this->access = array_merge(array_diff((array) $access, $this->access), $this->access); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | public function denyAccess($access) |
429 | 429 | { |
430 | 430 | // $this->removeButtons((array)$access); |
431 | - return $this->access = array_diff($this->access, (array)$access); |
|
431 | + return $this->access = array_diff($this->access, (array) $access); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | */ |
642 | 642 | public function addDefaultTypeToColumn($column) |
643 | 643 | { |
644 | - if (array_key_exists('name', (array)$column)) |
|
644 | + if (array_key_exists('name', (array) $column)) |
|
645 | 645 | { |
646 | 646 | $default_type = $this->getFieldTypeFromDbColumnType($column['name']); |
647 | 647 | return array_merge(['type' => $default_type], $column); |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | * @param [field or column] |
658 | 658 | */ |
659 | 659 | public function addDefaultLabel($array) { |
660 | - if (!array_key_exists('label', (array)$array) && array_key_exists('name', (array)$array)) { |
|
660 | + if (!array_key_exists('label', (array) $array) && array_key_exists('name', (array) $array)) { |
|
661 | 661 | $array = array_merge(['label' => ucfirst($this->makeLabel($array['name']))], $array); |
662 | 662 | return $array; |
663 | 663 | } |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | array_map(function($field) { |
832 | 832 | // $this->labels[$field] = $this->makeLabel($field); |
833 | 833 | |
834 | - $this->fields[] = [ |
|
834 | + $this->fields[] = [ |
|
835 | 835 | 'name' => $field, |
836 | 836 | 'label' => ucfirst($field), |
837 | 837 | 'value' => '', 'default' => $this->field_types[$field]['default'], |
@@ -1173,7 +1173,7 @@ discard block |
||
1173 | 1173 | |
1174 | 1174 | public function orderColumns($order) |
1175 | 1175 | { |
1176 | - $this->setSort('columns', (array)$order); |
|
1176 | + $this->setSort('columns', (array) $order); |
|
1177 | 1177 | } |
1178 | 1178 | |
1179 | 1179 | |
@@ -1248,13 +1248,13 @@ discard block |
||
1248 | 1248 | |
1249 | 1249 | public function orderFields($order) |
1250 | 1250 | { |
1251 | - $this->setSort('fields', (array)$order); |
|
1251 | + $this->setSort('fields', (array) $order); |
|
1252 | 1252 | } |
1253 | 1253 | |
1254 | 1254 | |
1255 | 1255 | public function syncField($field) |
1256 | 1256 | { |
1257 | - if (array_key_exists('name', (array)$field)) return array_merge(['type' => $this->getFieldTypeFromDbColumnType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
|
1257 | + if (array_key_exists('name', (array) $field)) return array_merge(['type' => $this->getFieldTypeFromDbColumnType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
|
1258 | 1258 | |
1259 | 1259 | return false; |
1260 | 1260 | } |
@@ -1293,7 +1293,7 @@ discard block |
||
1293 | 1293 | if (!empty($this->{$type})) |
1294 | 1294 | { |
1295 | 1295 | $this->{$type} = array_map(function($field) use ($fields, $attributes) { |
1296 | - if (in_array($field['name'], (array)$fields)) $field = array_merge($field, $attributes); |
|
1296 | + if (in_array($field['name'], (array) $fields)) $field = array_merge($field, $attributes); |
|
1297 | 1297 | |
1298 | 1298 | return $field; |
1299 | 1299 | }, $this->{$type}); |
@@ -1304,7 +1304,7 @@ discard block |
||
1304 | 1304 | |
1305 | 1305 | public function remove($entity, $fields) |
1306 | 1306 | { |
1307 | - return array_values(array_filter($this->{$entity}, function($field) use ($fields) { return !in_array($field['name'], (array)$fields);})); |
|
1307 | + return array_values(array_filter($this->{$entity}, function($field) use ($fields) { return !in_array($field['name'], (array) $fields); })); |
|
1308 | 1308 | } |
1309 | 1309 | |
1310 | 1310 | public function setSort($items, $order) |
@@ -1323,7 +1323,7 @@ discard block |
||
1323 | 1323 | if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) $elements[] = $this->{$items}[$key]; |
1324 | 1324 | } |
1325 | 1325 | |
1326 | - return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]);})); |
|
1326 | + return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]); })); |
|
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | return $this->{$items}; |
@@ -1336,7 +1336,7 @@ discard block |
||
1336 | 1336 | // cred ca ia valorile din tabela de legatura ca sa ti le afiseze in select |
1337 | 1337 | public function getRelationValues($model, $field, $where = [], $order = []) |
1338 | 1338 | { |
1339 | - $order = (array)$order; |
|
1339 | + $order = (array) $order; |
|
1340 | 1340 | $values = $model->select('*'); |
1341 | 1341 | |
1342 | 1342 | if (!empty($where)) call_user_func_array([$values, $where[0]], array_slice($where, 1)); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | { |
94 | 94 | if( $form == 'create' ){ |
95 | 95 | $fields = empty($this->create_fields)?$this->fields:$this->create_fields; |
96 | - }else{ |
|
96 | + } else{ |
|
97 | 97 | $fields = empty($this->update_fields)?$this->fields:$this->update_fields; |
98 | 98 | } |
99 | 99 | |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | foreach($relation['name'] as $relation){ |
122 | 122 | if(isset($data[$relation])){ |
123 | 123 | $model->{$relation}()->sync($data[$relation]); |
124 | - }else{ |
|
124 | + } else{ |
|
125 | 125 | $model->{$relation}()->sync([]); |
126 | 126 | } |
127 | 127 | } |
128 | - }else{ |
|
128 | + } else{ |
|
129 | 129 | $model->{$relation['name']}()->sync($data[$relation['name']]); |
130 | 130 | } |
131 | 131 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $fields[$k]['value'][] = $entry->{$relation}; |
304 | 304 | } |
305 | 305 | |
306 | - }else{ |
|
306 | + } else{ |
|
307 | 307 | $fields[$k]['value'] = $entry->{$field['name']}; |
308 | 308 | } |
309 | 309 | } |
@@ -482,7 +482,9 @@ discard block |
||
482 | 482 | */ |
483 | 483 | public function setModel($model_namespace) |
484 | 484 | { |
485 | - if (!class_exists($model_namespace)) throw new \Exception('This model does not exist.', 404); |
|
485 | + if (!class_exists($model_namespace)) { |
|
486 | + throw new \Exception('This model does not exist.', 404); |
|
487 | + } |
|
486 | 488 | |
487 | 489 | $this->model = new $model_namespace(); |
488 | 490 | $this->query = $this->model->select('*'); |
@@ -524,7 +526,9 @@ discard block |
||
524 | 526 | { |
525 | 527 | $complete_route = $route.'.index'; |
526 | 528 | |
527 | - if (!\Route::has($complete_route)) throw new \Exception('There are no routes for this route name.', 404); |
|
529 | + if (!\Route::has($complete_route)) { |
|
530 | + throw new \Exception('There are no routes for this route name.', 404); |
|
531 | + } |
|
528 | 532 | |
529 | 533 | $this->route = route($complete_route, $parameters); |
530 | 534 | $this->initButtons(); |
@@ -580,8 +584,7 @@ discard block |
||
580 | 584 | // if label and other details have been defined in the array |
581 | 585 | if (is_array($columns[0])) { |
582 | 586 | $this->addColumn($column); |
583 | - } |
|
584 | - else |
|
587 | + } else |
|
585 | 588 | { |
586 | 589 | $this->addColumn([ |
587 | 590 | 'name' => $column, |
@@ -877,11 +880,17 @@ discard block |
||
877 | 880 | */ |
878 | 881 | public function getFieldTypeFromDbColumnType($field) |
879 | 882 | { |
880 | - if (!array_key_exists($field, $this->field_types)) return 'text'; |
|
883 | + if (!array_key_exists($field, $this->field_types)) { |
|
884 | + return 'text'; |
|
885 | + } |
|
881 | 886 | |
882 | - if ($field == 'password') return 'password'; |
|
887 | + if ($field == 'password') { |
|
888 | + return 'password'; |
|
889 | + } |
|
883 | 890 | |
884 | - if ($field == 'email') return 'email'; |
|
891 | + if ($field == 'email') { |
|
892 | + return 'email'; |
|
893 | + } |
|
885 | 894 | |
886 | 895 | switch ($this->field_types[$field]['type']) |
887 | 896 | { |
@@ -954,7 +963,9 @@ discard block |
||
954 | 963 | $columns = \Schema::getColumnListing($this->model->getTable()); |
955 | 964 | $fillable = $this->model->getFillable(); |
956 | 965 | |
957 | - if (!empty($fillable)) $columns = array_intersect($columns, $fillable); |
|
966 | + if (!empty($fillable)) { |
|
967 | + $columns = array_intersect($columns, $fillable); |
|
968 | + } |
|
958 | 969 | |
959 | 970 | // but not updated_at, deleted_at |
960 | 971 | return array_values(array_diff($columns, [$this->model->getKeyName(), 'updated_at', 'deleted_at'])); |
@@ -1254,7 +1265,9 @@ discard block |
||
1254 | 1265 | |
1255 | 1266 | public function syncField($field) |
1256 | 1267 | { |
1257 | - if (array_key_exists('name', (array)$field)) return array_merge(['type' => $this->getFieldTypeFromDbColumnType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
|
1268 | + if (array_key_exists('name', (array)$field)) { |
|
1269 | + return array_merge(['type' => $this->getFieldTypeFromDbColumnType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
|
1270 | + } |
|
1258 | 1271 | |
1259 | 1272 | return false; |
1260 | 1273 | } |
@@ -1272,8 +1285,11 @@ discard block |
||
1272 | 1285 | |
1273 | 1286 | foreach ($this->{$fields} as $key => $field) |
1274 | 1287 | { |
1275 | - if (array_key_exists($field['name'], $this->relations) && $this->relations[$field['name']]['pivot']) $this->{$fields}[$key]['value'] = $this->entry->{$this->relations[$field['name']]['name']}()->lists($this->relations[$field['name']]['model']->getKeyName())->toArray(); |
|
1276 | - else $this->{$fields}[$key]['value'] = $this->entry->{$field['name']}; |
|
1288 | + if (array_key_exists($field['name'], $this->relations) && $this->relations[$field['name']]['pivot']) { |
|
1289 | + $this->{$fields}[$key]['value'] = $this->entry->{$this->relations[$field['name']]['name']}()->lists($this->relations[$field['name']]['model']->getKeyName())->toArray(); |
|
1290 | + } else { |
|
1291 | + $this->{$fields}[$key]['value'] = $this->entry->{$field['name']}; |
|
1292 | + } |
|
1277 | 1293 | } |
1278 | 1294 | } |
1279 | 1295 | } |
@@ -1293,7 +1309,9 @@ discard block |
||
1293 | 1309 | if (!empty($this->{$type})) |
1294 | 1310 | { |
1295 | 1311 | $this->{$type} = array_map(function($field) use ($fields, $attributes) { |
1296 | - if (in_array($field['name'], (array)$fields)) $field = array_merge($field, $attributes); |
|
1312 | + if (in_array($field['name'], (array)$fields)) { |
|
1313 | + $field = array_merge($field, $attributes); |
|
1314 | + } |
|
1297 | 1315 | |
1298 | 1316 | return $field; |
1299 | 1317 | }, $this->{$type}); |
@@ -1320,7 +1338,9 @@ discard block |
||
1320 | 1338 | |
1321 | 1339 | foreach ($this->sort[$items] as $item) |
1322 | 1340 | { |
1323 | - if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) $elements[] = $this->{$items}[$key]; |
|
1341 | + if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) { |
|
1342 | + $elements[] = $this->{$items}[$key]; |
|
1343 | + } |
|
1324 | 1344 | } |
1325 | 1345 | |
1326 | 1346 | return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]);})); |
@@ -1339,9 +1359,13 @@ discard block |
||
1339 | 1359 | $order = (array)$order; |
1340 | 1360 | $values = $model->select('*'); |
1341 | 1361 | |
1342 | - if (!empty($where)) call_user_func_array([$values, $where[0]], array_slice($where, 1)); |
|
1362 | + if (!empty($where)) { |
|
1363 | + call_user_func_array([$values, $where[0]], array_slice($where, 1)); |
|
1364 | + } |
|
1343 | 1365 | |
1344 | - if (!empty($order)) call_user_func_array([$values, 'orderBy'], $order); |
|
1366 | + if (!empty($order)) { |
|
1367 | + call_user_func_array([$values, 'orderBy'], $order); |
|
1368 | + } |
|
1345 | 1369 | |
1346 | 1370 | return $values->get()->lists($field, $model->getKeyName())->toArray(); |
1347 | 1371 | } |
@@ -1350,8 +1374,11 @@ discard block |
||
1350 | 1374 | public function syncRelations($entity) |
1351 | 1375 | { |
1352 | 1376 | foreach ($this->relations as $field => $relation) { |
1353 | - if ($relation['pivot']) $this->add($entity, ['name' => $field, 'type' => 'multiselect', 'value' => [], 'values' => $this->relations[$field]['values']]); |
|
1354 | - else $this->sync($entity, $field, ['type' => 'select', 'values' => $this->relations[$field]['values']]); |
|
1377 | + if ($relation['pivot']) { |
|
1378 | + $this->add($entity, ['name' => $field, 'type' => 'multiselect', 'value' => [], 'values' => $this->relations[$field]['values']]); |
|
1379 | + } else { |
|
1380 | + $this->sync($entity, $field, ['type' => 'select', 'values' => $this->relations[$field]['values']]); |
|
1381 | + } |
|
1355 | 1382 | } |
1356 | 1383 | } |
1357 | 1384 |
@@ -38,6 +38,9 @@ discard block |
||
38 | 38 | $this->initState(); |
39 | 39 | } |
40 | 40 | |
41 | + /** |
|
42 | + * @param string $model |
|
43 | + */ |
|
41 | 44 | public function setModel($model) |
42 | 45 | { |
43 | 46 | if (!class_exists($model)) throw new \Exception('This model does not exist.', 404); |
@@ -54,6 +57,10 @@ discard block |
||
54 | 57 | } |
55 | 58 | |
56 | 59 | // TODO: make this work without having to specify "index" |
60 | + |
|
61 | + /** |
|
62 | + * @param string $route |
|
63 | + */ |
|
57 | 64 | public function setRoute($route, $parameters = []) |
58 | 65 | { |
59 | 66 | if (!\Route::has($route)) throw new \Exception('This route does not exist.', 404); |
@@ -259,6 +266,9 @@ discard block |
||
259 | 266 | return $model; |
260 | 267 | } |
261 | 268 | |
269 | + /** |
|
270 | + * @param integer $id |
|
271 | + */ |
|
262 | 272 | public function delete($id) // DONE |
263 | 273 | { |
264 | 274 | return $this->model->destroy($id); |
@@ -489,6 +499,9 @@ discard block |
||
489 | 499 | return array_filter($this->{$entity}[] = $this->syncField($field)); |
490 | 500 | } |
491 | 501 | |
502 | + /** |
|
503 | + * @param string $entity |
|
504 | + */ |
|
492 | 505 | private function addMultiple($entity, $field) |
493 | 506 | { |
494 | 507 | $this->{$entity} = array_filter(array_map([$this, 'syncField'], $fields)); |
@@ -506,16 +519,25 @@ discard block |
||
506 | 519 | } |
507 | 520 | } |
508 | 521 | |
522 | + /** |
|
523 | + * @param string $entity |
|
524 | + */ |
|
509 | 525 | private function remove($entity, $fields) |
510 | 526 | { |
511 | 527 | return array_values(array_filter($this->{$entity}, function($field) use ($fields) { return !in_array($field['name'], (array)$fields);})); |
512 | 528 | } |
513 | 529 | |
530 | + /** |
|
531 | + * @param string $items |
|
532 | + */ |
|
514 | 533 | private function setSort($items, $order) |
515 | 534 | { |
516 | 535 | $this->sort[$items] = $order; |
517 | 536 | } |
518 | 537 | |
538 | + /** |
|
539 | + * @param string $items |
|
540 | + */ |
|
519 | 541 | private function sort($items) |
520 | 542 | { |
521 | 543 | if (array_key_exists($items, $this->sort)) |
@@ -561,6 +583,9 @@ discard block |
||
561 | 583 | return $values->get()->lists($field, $model->getKeyName())->toArray(); |
562 | 584 | } |
563 | 585 | |
586 | + /** |
|
587 | + * @param string $entity |
|
588 | + */ |
|
564 | 589 | private function syncRelations($entity) |
565 | 590 | { |
566 | 591 | foreach ($this->relations as $field => $relation) { |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | |
191 | 191 | public function addCreateField($field) |
192 | 192 | { |
193 | - return $this->add('createFields', $field); |
|
193 | + return $this->add('createFields', $field); |
|
194 | 194 | } |
195 | 195 | |
196 | - public function setUpdateFields($fields) |
|
196 | + public function setUpdateFields($fields) |
|
197 | 197 | { |
198 | 198 | $this->addMultiple('updateFields', $fields); |
199 | 199 | } |
@@ -541,9 +541,9 @@ discard block |
||
541 | 541 | $model->{$relation['name']}()->sync($data[$key]); |
542 | 542 | |
543 | 543 | foreach($relation['pivotFields'] as $pivotField){ |
544 | - foreach($data[$pivotField] as $pivot_id => $field){ |
|
545 | - $model->{$relation['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]); |
|
546 | - } |
|
544 | + foreach($data[$pivotField] as $pivot_id => $field){ |
|
545 | + $model->{$relation['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]); |
|
546 | + } |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | } |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | |
126 | 126 | public function removePermissions($permissions) // DONE |
127 | 127 | { |
128 | - $this->removeButtons((array)$permissions); |
|
128 | + $this->removeButtons((array) $permissions); |
|
129 | 129 | |
130 | - return $this->permissions = array_diff($this->permissions, (array)$permissions); |
|
130 | + return $this->permissions = array_diff($this->permissions, (array) $permissions); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | public function setColumns($columns) |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | public function orderColumns($order) |
160 | 160 | { |
161 | - $this->setSort('columns', (array)$order); |
|
161 | + $this->setSort('columns', (array) $order); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | public function setFields($fields) |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | |
229 | 229 | public function orderFields($order) |
230 | 230 | { |
231 | - $this->setSort('fields', (array)$order); |
|
231 | + $this->setSort('fields', (array) $order); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | public function items() |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | public function unsetListActions($actions) |
289 | 289 | { |
290 | - return $this->listActions = array_diff($this->listActions, (array)$actions); |
|
290 | + return $this->listActions = array_diff($this->listActions, (array) $actions); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | public function checkListAction($action) |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | |
313 | 313 | public function setRequired($fields) |
314 | 314 | { |
315 | - $this->required = array_merge($this->required, (array)$fields); |
|
315 | + $this->required = array_merge($this->required, (array) $fields); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | public function required() |
@@ -380,14 +380,14 @@ discard block |
||
380 | 380 | |
381 | 381 | private function syncColumn($column) |
382 | 382 | { |
383 | - if (array_key_exists('name', (array)$column)) return array_merge(['type' => $this->getType($column['name'])], $column); |
|
383 | + if (array_key_exists('name', (array) $column)) return array_merge(['type' => $this->getType($column['name'])], $column); |
|
384 | 384 | |
385 | 385 | return false; |
386 | 386 | } |
387 | 387 | |
388 | 388 | private function syncField($field) |
389 | 389 | { |
390 | - if (array_key_exists('name', (array)$field)) return array_merge(['type' => $this->getType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
|
390 | + if (array_key_exists('name', (array) $field)) return array_merge(['type' => $this->getType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
|
391 | 391 | |
392 | 392 | return false; |
393 | 393 | } |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | if (!empty($this->{$type})) |
500 | 500 | { |
501 | 501 | $this->{$type} = array_map(function($field) use ($fields, $attributes) { |
502 | - if (in_array($field['name'], (array)$fields)) $field = array_merge($field, $attributes); |
|
502 | + if (in_array($field['name'], (array) $fields)) $field = array_merge($field, $attributes); |
|
503 | 503 | |
504 | 504 | return $field; |
505 | 505 | }, $this->{$type}); |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | |
509 | 509 | private function remove($entity, $fields) |
510 | 510 | { |
511 | - return array_values(array_filter($this->{$entity}, function($field) use ($fields) { return !in_array($field['name'], (array)$fields);})); |
|
511 | + return array_values(array_filter($this->{$entity}, function($field) use ($fields) { return !in_array($field['name'], (array) $fields); })); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | private function setSort($items, $order) |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) $elements[] = $this->{$items}[$key]; |
528 | 528 | } |
529 | 529 | |
530 | - return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]);})); |
|
530 | + return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]); })); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | return $this->{$items}; |
@@ -537,11 +537,11 @@ discard block |
||
537 | 537 | { |
538 | 538 | foreach ($this->relations as $key => $relation) |
539 | 539 | { |
540 | - if ($relation['pivot']){ |
|
540 | + if ($relation['pivot']) { |
|
541 | 541 | $model->{$relation['name']}()->sync($data[$key]); |
542 | 542 | |
543 | - foreach($relation['pivotFields'] as $pivotField){ |
|
544 | - foreach($data[$pivotField] as $pivot_id => $field){ |
|
543 | + foreach ($relation['pivotFields'] as $pivotField) { |
|
544 | + foreach ($data[$pivotField] as $pivot_id => $field) { |
|
545 | 545 | $model->{$relation['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]); |
546 | 546 | } |
547 | 547 | } |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | |
552 | 552 | private function getRelationValues($model, $field, $where = [], $order = []) |
553 | 553 | { |
554 | - $order = (array)$order; |
|
554 | + $order = (array) $order; |
|
555 | 555 | $values = $model->select('*'); |
556 | 556 | |
557 | 557 | if (!empty($where)) call_user_func_array([$values, $where[0]], array_slice($where, 1)); |
@@ -40,7 +40,9 @@ discard block |
||
40 | 40 | |
41 | 41 | public function setModel($model) |
42 | 42 | { |
43 | - if (!class_exists($model)) throw new \Exception('This model does not exist.', 404); |
|
43 | + if (!class_exists($model)) { |
|
44 | + throw new \Exception('This model does not exist.', 404); |
|
45 | + } |
|
44 | 46 | |
45 | 47 | $this->model = new $model(); |
46 | 48 | $this->query = $this->model->select('*'); |
@@ -56,7 +58,9 @@ discard block |
||
56 | 58 | // TODO: make this work without having to specify "index" |
57 | 59 | public function setRoute($route, $parameters = []) |
58 | 60 | { |
59 | - if (!\Route::has($route)) throw new \Exception('This route does not exist.', 404); |
|
61 | + if (!\Route::has($route)) { |
|
62 | + throw new \Exception('This route does not exist.', 404); |
|
63 | + } |
|
60 | 64 | |
61 | 65 | $this->route = route($route, $parameters); |
62 | 66 | $this->initButtons(); |
@@ -254,7 +258,9 @@ discard block |
||
254 | 258 | { |
255 | 259 | $model = $this->model->findOrFail($id); |
256 | 260 | $updated = $model->update($data); |
257 | - if ($updated) $this->syncPivot($model, $data); |
|
261 | + if ($updated) { |
|
262 | + $this->syncPivot($model, $data); |
|
263 | + } |
|
258 | 264 | |
259 | 265 | return $model; |
260 | 266 | } |
@@ -282,7 +288,9 @@ discard block |
||
282 | 288 | |
283 | 289 | public function checkPermission($permission) // DONE |
284 | 290 | { |
285 | - if (!in_array($permission, $this->permissions)) abort(403); |
|
291 | + if (!in_array($permission, $this->permissions)) { |
|
292 | + abort(403); |
|
293 | + } |
|
286 | 294 | } |
287 | 295 | |
288 | 296 | public function unsetListActions($actions) |
@@ -351,11 +359,17 @@ discard block |
||
351 | 359 | |
352 | 360 | $this->state = 'list'; |
353 | 361 | |
354 | - if (in_array('create', $segments)) $this->state = 'add'; |
|
362 | + if (in_array('create', $segments)) { |
|
363 | + $this->state = 'add'; |
|
364 | + } |
|
355 | 365 | |
356 | - if (in_array('edit', $segments)) $this->state = 'edit'; |
|
366 | + if (in_array('edit', $segments)) { |
|
367 | + $this->state = 'edit'; |
|
368 | + } |
|
357 | 369 | |
358 | - if (is_numeric(end($segments))) $this->state = 'view'; |
|
370 | + if (is_numeric(end($segments))) { |
|
371 | + $this->state = 'view'; |
|
372 | + } |
|
359 | 373 | } |
360 | 374 | |
361 | 375 | private function removeButtons($buttons) |
@@ -373,21 +387,27 @@ discard block |
||
373 | 387 | $columns = \Schema::getColumnListing($this->model->getTable()); |
374 | 388 | $fillable = $this->model->getFillable(); |
375 | 389 | |
376 | - if (!empty($fillable)) $columns = array_intersect($columns, $fillable); |
|
390 | + if (!empty($fillable)) { |
|
391 | + $columns = array_intersect($columns, $fillable); |
|
392 | + } |
|
377 | 393 | |
378 | 394 | return array_values(array_diff($columns, [$this->model->getKeyName(), 'updated_at', 'deleted_at'])); |
379 | 395 | } |
380 | 396 | |
381 | 397 | private function syncColumn($column) |
382 | 398 | { |
383 | - if (array_key_exists('name', (array)$column)) return array_merge(['type' => $this->getType($column['name'])], $column); |
|
399 | + if (array_key_exists('name', (array)$column)) { |
|
400 | + return array_merge(['type' => $this->getType($column['name'])], $column); |
|
401 | + } |
|
384 | 402 | |
385 | 403 | return false; |
386 | 404 | } |
387 | 405 | |
388 | 406 | private function syncField($field) |
389 | 407 | { |
390 | - if (array_key_exists('name', (array)$field)) return array_merge(['type' => $this->getType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
|
408 | + if (array_key_exists('name', (array)$field)) { |
|
409 | + return array_merge(['type' => $this->getType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
|
410 | + } |
|
391 | 411 | |
392 | 412 | return false; |
393 | 413 | } |
@@ -404,11 +424,17 @@ discard block |
||
404 | 424 | |
405 | 425 | private function getType($field) // DONE |
406 | 426 | { |
407 | - if (!array_key_exists($field, $this->fieldTypes)) return 'text'; |
|
427 | + if (!array_key_exists($field, $this->fieldTypes)) { |
|
428 | + return 'text'; |
|
429 | + } |
|
408 | 430 | |
409 | - if ($field == 'password') return 'password'; |
|
431 | + if ($field == 'password') { |
|
432 | + return 'password'; |
|
433 | + } |
|
410 | 434 | |
411 | - if ($field == 'email') return 'email'; |
|
435 | + if ($field == 'email') { |
|
436 | + return 'email'; |
|
437 | + } |
|
412 | 438 | |
413 | 439 | switch ($this->fieldTypes[$field]['type']) |
414 | 440 | { |
@@ -466,7 +492,9 @@ discard block |
||
466 | 492 | |
467 | 493 | $this->fields[] = ['name' => $field, 'value' => '', 'default' => $this->fieldTypes[$field]['default'], 'type' => $this->getType($field), 'values' => [], 'attributes' => []]; |
468 | 494 | |
469 | - if (!in_array($field, $this->model->getHidden())) $this->columns[] = ['name' => $field, 'type' => $this->getType($field)]; |
|
495 | + if (!in_array($field, $this->model->getHidden())) { |
|
496 | + $this->columns[] = ['name' => $field, 'type' => $this->getType($field)]; |
|
497 | + } |
|
470 | 498 | }, $this->getColumns()); |
471 | 499 | } |
472 | 500 | |
@@ -478,8 +506,11 @@ discard block |
||
478 | 506 | |
479 | 507 | foreach ($this->{$fields} as $key => $field) |
480 | 508 | { |
481 | - if (array_key_exists($field['name'], $this->relations) && $this->relations[$field['name']]['pivot']) $this->{$fields}[$key]['value'] = $this->item->{$this->relations[$field['name']]['name']}()->lists($this->relations[$field['name']]['model']->getKeyName())->toArray(); |
|
482 | - else $this->{$fields}[$key]['value'] = $this->item->{$field['name']}; |
|
509 | + if (array_key_exists($field['name'], $this->relations) && $this->relations[$field['name']]['pivot']) { |
|
510 | + $this->{$fields}[$key]['value'] = $this->item->{$this->relations[$field['name']]['name']}()->lists($this->relations[$field['name']]['model']->getKeyName())->toArray(); |
|
511 | + } else { |
|
512 | + $this->{$fields}[$key]['value'] = $this->item->{$field['name']}; |
|
513 | + } |
|
483 | 514 | } |
484 | 515 | } |
485 | 516 | } |
@@ -499,7 +530,9 @@ discard block |
||
499 | 530 | if (!empty($this->{$type})) |
500 | 531 | { |
501 | 532 | $this->{$type} = array_map(function($field) use ($fields, $attributes) { |
502 | - if (in_array($field['name'], (array)$fields)) $field = array_merge($field, $attributes); |
|
533 | + if (in_array($field['name'], (array)$fields)) { |
|
534 | + $field = array_merge($field, $attributes); |
|
535 | + } |
|
503 | 536 | |
504 | 537 | return $field; |
505 | 538 | }, $this->{$type}); |
@@ -524,7 +557,9 @@ discard block |
||
524 | 557 | |
525 | 558 | foreach ($this->sort[$items] as $item) |
526 | 559 | { |
527 | - if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) $elements[] = $this->{$items}[$key]; |
|
560 | + if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) { |
|
561 | + $elements[] = $this->{$items}[$key]; |
|
562 | + } |
|
528 | 563 | } |
529 | 564 | |
530 | 565 | return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]);})); |
@@ -554,9 +589,13 @@ discard block |
||
554 | 589 | $order = (array)$order; |
555 | 590 | $values = $model->select('*'); |
556 | 591 | |
557 | - if (!empty($where)) call_user_func_array([$values, $where[0]], array_slice($where, 1)); |
|
592 | + if (!empty($where)) { |
|
593 | + call_user_func_array([$values, $where[0]], array_slice($where, 1)); |
|
594 | + } |
|
558 | 595 | |
559 | - if (!empty($order)) call_user_func_array([$values, 'orderBy'], $order); |
|
596 | + if (!empty($order)) { |
|
597 | + call_user_func_array([$values, 'orderBy'], $order); |
|
598 | + } |
|
560 | 599 | |
561 | 600 | return $values->get()->lists($field, $model->getKeyName())->toArray(); |
562 | 601 | } |
@@ -564,8 +603,11 @@ discard block |
||
564 | 603 | private function syncRelations($entity) |
565 | 604 | { |
566 | 605 | foreach ($this->relations as $field => $relation) { |
567 | - if ($relation['pivot']) $this->add($entity, ['name' => $field, 'type' => 'multiselect', 'value' => [], 'values' => $this->relations[$field]['values']]); |
|
568 | - else $this->sync($entity, $field, ['type' => 'select', 'values' => $this->relations[$field]['values']]); |
|
606 | + if ($relation['pivot']) { |
|
607 | + $this->add($entity, ['name' => $field, 'type' => 'multiselect', 'value' => [], 'values' => $this->relations[$field]['values']]); |
|
608 | + } else { |
|
609 | + $this->sync($entity, $field, ['type' => 'select', 'values' => $this->relations[$field]['values']]); |
|
610 | + } |
|
569 | 611 | } |
570 | 612 | } |
571 | 613 |
@@ -20,42 +20,42 @@ discard block |
||
20 | 20 | |
21 | 21 | @section('content') |
22 | 22 | <?php |
23 | - function tree_element($entry, $key, $all_entries, $crud) |
|
24 | - { |
|
23 | + function tree_element($entry, $key, $all_entries, $crud) |
|
24 | + { |
|
25 | 25 | if (!isset($entry->tree_element_shown)) { |
26 | - // mark the element as shown |
|
27 | - $all_entries[$key]->tree_element_shown = true; |
|
28 | - $entry->tree_element_shown = true; |
|
26 | + // mark the element as shown |
|
27 | + $all_entries[$key]->tree_element_shown = true; |
|
28 | + $entry->tree_element_shown = true; |
|
29 | 29 | |
30 | - // show the tree element |
|
31 | - echo '<li id="list_'.$entry->id.'">'; |
|
32 | - echo '<div><span class="disclose"><span></span></span>'.$entry->{$crud->reorder_label}.'</div>'; |
|
30 | + // show the tree element |
|
31 | + echo '<li id="list_'.$entry->id.'">'; |
|
32 | + echo '<div><span class="disclose"><span></span></span>'.$entry->{$crud->reorder_label}.'</div>'; |
|
33 | 33 | |
34 | - // see if this element has any children |
|
35 | - $children = []; |
|
36 | - foreach ($all_entries as $key => $subentry) { |
|
34 | + // see if this element has any children |
|
35 | + $children = []; |
|
36 | + foreach ($all_entries as $key => $subentry) { |
|
37 | 37 | if ($subentry->parent_id == $entry->id) { |
38 | - $children[] = $subentry; |
|
38 | + $children[] = $subentry; |
|
39 | + } |
|
39 | 40 | } |
40 | - } |
|
41 | 41 | |
42 | - $children = collect($children)->sortBy('lft'); |
|
42 | + $children = collect($children)->sortBy('lft'); |
|
43 | 43 | |
44 | - // if it does have children, show them |
|
45 | - if (count($children)) { |
|
44 | + // if it does have children, show them |
|
45 | + if (count($children)) { |
|
46 | 46 | echo '<ol>'; |
47 | 47 | foreach ($children as $key => $child) { |
48 | - $children[$key] = tree_element($child, $child->id, $all_entries, $crud); |
|
48 | + $children[$key] = tree_element($child, $child->id, $all_entries, $crud); |
|
49 | 49 | } |
50 | 50 | echo '</ol>'; |
51 | - } |
|
52 | - echo '</li>'; |
|
51 | + } |
|
52 | + echo '</li>'; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return $entry; |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - ?> |
|
58 | + ?> |
|
59 | 59 | <div class="row"> |
60 | 60 | <div class="col-md-8 col-md-offset-2"> |
61 | 61 | @if ($crud->hasAccess('list')) |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | |
88 | 88 | <ol class="sortable"> |
89 | 89 | <?php |
90 | - $all_entries = collect($entries->all())->sortBy('lft')->keyBy('id'); |
|
91 | - $root_entries = $all_entries->filter(function($item) { |
|
90 | + $all_entries = collect($entries->all())->sortBy('lft')->keyBy('id'); |
|
91 | + $root_entries = $all_entries->filter(function($item) { |
|
92 | 92 | return $item->parent_id == 0; |
93 | - }); |
|
94 | - ?> |
|
93 | + }); |
|
94 | + ?> |
|
95 | 95 | @foreach ($root_entries as $key => $entry) |
96 | 96 | <?php |
97 | 97 | $root_entries[$key] = tree_element($entry, $key, $all_entries, $crud); |
98 | - ?> |
|
98 | + ?> |
|
99 | 99 | @endforeach |
100 | 100 | </ol> |
101 | 101 |
@@ -2,34 +2,34 @@ discard block |
||
2 | 2 | <div class="form-group checklist_dependency" data-entity ="{{ $field['field_unique_name'] }}"> |
3 | 3 | <label>{{ $field['label'] }}</label> |
4 | 4 | <?php |
5 | - $entity_model = $crud->getModel(); |
|
5 | + $entity_model = $crud->getModel(); |
|
6 | 6 | |
7 | - //short name for dependency fields |
|
8 | - $primary_dependency = $field['dependencies']['primary']; |
|
9 | - $secondary_dependency = $field['dependencies']['secondary']; |
|
7 | + //short name for dependency fields |
|
8 | + $primary_dependency = $field['dependencies']['primary']; |
|
9 | + $secondary_dependency = $field['dependencies']['secondary']; |
|
10 | 10 | |
11 | 11 | |
12 | - //all items with relation |
|
13 | - $dependencies = $primary_dependency['model']::with($primary_dependency['entity_secondary'])->get(); |
|
12 | + //all items with relation |
|
13 | + $dependencies = $primary_dependency['model']::with($primary_dependency['entity_secondary'])->get(); |
|
14 | 14 | |
15 | - $dependencyArray = []; |
|
15 | + $dependencyArray = []; |
|
16 | 16 | |
17 | - //convert dependency array to simple matrix ( prymary id as key and array with secondaries id ) |
|
18 | - foreach($dependencies as $primary){ |
|
19 | - $dependencyArray[$primary->id] = []; |
|
17 | + //convert dependency array to simple matrix ( prymary id as key and array with secondaries id ) |
|
18 | + foreach($dependencies as $primary){ |
|
19 | + $dependencyArray[$primary->id] = []; |
|
20 | 20 | foreach($primary->{$primary_dependency['entity_secondary']} as $secondary){ |
21 | 21 | $dependencyArray[$primary->id][] = $secondary->id; |
22 | 22 | } |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - //for update form, get initial state of the entity |
|
26 | - if( isset($id) && $id ){ |
|
25 | + //for update form, get initial state of the entity |
|
26 | + if( isset($id) && $id ){ |
|
27 | 27 | |
28 | 28 | //get entity with relations for primary dependency |
29 | 29 | $entity_dependencies = $entity_model->with($primary_dependency['entity']) |
30 | - ->with($primary_dependency['entity'].'.'.$primary_dependency['entity_secondary']) |
|
31 | - ->where('id', $id) |
|
32 | - ->first(); |
|
30 | + ->with($primary_dependency['entity'].'.'.$primary_dependency['entity_secondary']) |
|
31 | + ->where('id', $id) |
|
32 | + ->first(); |
|
33 | 33 | |
34 | 34 | $secondaries_from_primary = []; |
35 | 35 | |
@@ -40,23 +40,23 @@ discard block |
||
40 | 40 | |
41 | 41 | //create secondary dependency from primary relation, used to check what chekbox must be check from second checklist |
42 | 42 | if( old($primary_dependency['name']) ) { |
43 | - foreach( old($primary_dependency['name']) as $primary_item ){ |
|
43 | + foreach( old($primary_dependency['name']) as $primary_item ){ |
|
44 | 44 | foreach($dependencyArray[$primary_item] as $second_item ){ |
45 | 45 | $secondary_ids[$second_item] = $second_item; |
46 | 46 | } |
47 | - } |
|
47 | + } |
|
48 | 48 | }else{ //create dependecies from relation if not from validate error |
49 | - foreach( $primary_array as $primary_item ){ |
|
49 | + foreach( $primary_array as $primary_item ){ |
|
50 | 50 | foreach($primary_item[$secondary_dependency['entity']] as $second_item ){ |
51 | 51 | $secondary_ids[$second_item['id']] = $second_item['id']; |
52 | 52 | } |
53 | - } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - //json encode of dependency matrix |
|
59 | - $dependencyJson = json_encode($dependencyArray); |
|
58 | + //json encode of dependency matrix |
|
59 | + $dependencyJson = json_encode($dependencyArray); |
|
60 | 60 | ?> |
61 | 61 | <script> |
62 | 62 | var {{ $field['field_unique_name'] }} = {!! $dependencyJson !!}; |
@@ -15,15 +15,15 @@ discard block |
||
15 | 15 | $dependencyArray = []; |
16 | 16 | |
17 | 17 | //convert dependency array to simple matrix ( prymary id as key and array with secondaries id ) |
18 | - foreach($dependencies as $primary){ |
|
18 | + foreach ($dependencies as $primary) { |
|
19 | 19 | $dependencyArray[$primary->id] = []; |
20 | - foreach($primary->{$primary_dependency['entity_secondary']} as $secondary){ |
|
20 | + foreach ($primary->{$primary_dependency['entity_secondary']} as $secondary) { |
|
21 | 21 | $dependencyArray[$primary->id][] = $secondary->id; |
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | 25 | //for update form, get initial state of the entity |
26 | - if( isset($id) && $id ){ |
|
26 | + if (isset($id) && $id) { |
|
27 | 27 | |
28 | 28 | //get entity with relations for primary dependency |
29 | 29 | $entity_dependencies = $entity_model->with($primary_dependency['entity']) |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | $secondary_ids = []; |
40 | 40 | |
41 | 41 | //create secondary dependency from primary relation, used to check what chekbox must be check from second checklist |
42 | - if( old($primary_dependency['name']) ) { |
|
43 | - foreach( old($primary_dependency['name']) as $primary_item ){ |
|
44 | - foreach($dependencyArray[$primary_item] as $second_item ){ |
|
42 | + if (old($primary_dependency['name'])) { |
|
43 | + foreach (old($primary_dependency['name']) as $primary_item) { |
|
44 | + foreach ($dependencyArray[$primary_item] as $second_item) { |
|
45 | 45 | $secondary_ids[$second_item] = $second_item; |
46 | 46 | } |
47 | 47 | } |
48 | - }else{ //create dependecies from relation if not from validate error |
|
49 | - foreach( $primary_array as $primary_item ){ |
|
50 | - foreach($primary_item[$secondary_dependency['entity']] as $second_item ){ |
|
48 | + } else { //create dependecies from relation if not from validate error |
|
49 | + foreach ($primary_array as $primary_item) { |
|
50 | + foreach ($primary_item[$secondary_dependency['entity']] as $second_item) { |
|
51 | 51 | $secondary_ids[$second_item['id']] = $second_item['id']; |
52 | 52 | } |
53 | 53 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | $secondary_ids[$second_item] = $second_item; |
46 | 46 | } |
47 | 47 | } |
48 | - }else{ //create dependecies from relation if not from validate error |
|
48 | + } else{ //create dependecies from relation if not from validate error |
|
49 | 49 | foreach( $primary_array as $primary_item ){ |
50 | 50 | foreach($primary_item[$secondary_dependency['entity']] as $second_item ){ |
51 | 51 | $secondary_ids[$second_item['id']] = $second_item['id']; |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <!-- select2 --> |
2 | 2 | <div class="form-group"> |
3 | 3 | <label>{{ $field['label'] }}</label> |
4 | - <?php $entity_model = $crud->getModel();?> |
|
4 | + <?php $entity_model = $crud->getModel(); ?> |
|
5 | 5 | |
6 | 6 | <div class="row"> |
7 | 7 | @foreach ($field['model']::all() as $connected_entity_entry) |
@@ -4,10 +4,7 @@ |
||
4 | 4 | */ |
5 | 5 | namespace Backpack\Crud\Http\Controllers; |
6 | 6 | |
7 | -use Illuminate\Foundation\Bus\DispatchesJobs; |
|
8 | 7 | use Illuminate\Routing\Controller as BaseController; |
9 | -use Illuminate\Foundation\Validation\ValidatesRequests; |
|
10 | -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
|
11 | 8 | use Backpack\Crud\Crud; |
12 | 9 | |
13 | 10 | /** |