Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Branch master (f5b2f7)
by Cristian
04:05
created
src/app/Http/Controllers/CrudController.php 1 patch
Indentation   +587 added lines, -587 removed lines patch added patch discarded remove patch
@@ -14,592 +14,592 @@
 block discarded – undo
14 14
 
15 15
 class CrudController extends BaseController {
16 16
 
17
-	use DispatchesJobs, ValidatesRequests;
18
-
19
-	public $data = array();
20
-	public $crud = array(
21
-						"model" => "\App\Models\Entity",
22
-						"entity_name" => "entry",
23
-						"entity_name_plural" => "entries",
24
-						"view_table_permission" => true,
25
-						"add_permission" => true,
26
-						"edit_permission" => true,
27
-						"delete_permission" => true,
28
-						"reorder_permission" => true,
29
-						"reorder_max_level" => 3,
30
-						"details_row" => false,
31
-						);
32
-
33
-	public function __construct()
34
-	{
35
-		$this->data['crud'] = $this->crud;
36
-
37
-		// Check for the right roles to access these pages
38
-		// if (!\Entrust::can('view-admin-panel')) {
39
-	 //        abort(403, trans('backpack::crud.unauthorized_access'));
40
-	 //    }
41
-	}
42
-
43
-	/**
44
-	 * Display all rows in the database for this entity.
45
-	 *
46
-	 * @return Response
47
-	 */
48
-	public function index()
49
-	{
50
-		// SECURITY:
51
-		// if view_table_permission is false, abort
52
-		if (isset($this->crud['view_table_permission']) && !$this->crud['view_table_permission']) {
53
-			abort(403, 'Not allowed.');
54
-		}
55
-
56
-		// get all results for that entity
57
-		$model = $this->crud['model'];
58
-		if (property_exists($model, 'translatable'))
59
-		{
60
-			$this->data['entries'] = $model::where('translation_lang', \Lang::locale())->get();
61
-		}
62
-		else
63
-		{
64
-			$this->data['entries'] = $model::all();
65
-		}
66
-
67
-			// add the fake fields for each entry
68
-			foreach ($this->data['entries'] as $key => $entry) {
69
-				$entry->addFakes($this->getFakeColumnsAsArray());
70
-			}
71
-
72
-		$this->prepareColumns();
73
-		$this->data['crud'] = $this->crud;
74
-		$this->data['title'] = ucfirst($this->crud['entity_name_plural']);
75
-
76
-		// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
77
-		return view('crud::list', $this->data);
78
-	}
79
-
80
-
81
-	/**
82
-	 * Show the form for creating inserting a new row.
83
-	 *
84
-	 * @return Response
85
-	 */
86
-	public function create()
87
-	{
88
-		// SECURITY:
89
-		// if add_permission is false, abort
90
-		if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) {
91
-			abort(403, 'Not allowed.');
92
-		}
93
-
94
-		// get the fields you need to show
95
-		if (isset($this->data['crud']['create_fields']))
96
-		{
97
-			$this->crud['fields'] = $this->data['crud']['create_fields'];
98
-		}
99
-
100
-		// prepare the fields you need to show
101
-		$this->prepareFields();
102
-		$this->data['crud'] = $this->crud;
103
-		$this->data['title'] = trans('backpack::crud.add').' '.$this->crud['entity_name'];
104
-
105
-		// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
106
-		return view('crud::create', $this->data);
107
-	}
108
-
109
-
110
-	/**
111
-	 * Store a newly created resource in the database.
112
-	 *
113
-	 * @return Response
114
-	 */
115
-	public function storeCrud(StoreRequest $request = null)
116
-	{
117
-		// SECURITY:
118
-		// if add_permission is false, abort
119
-		if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) {
120
-			abort(403, 'Not allowed.');
121
-		}
122
-
123
-		// compress the fake fields into one field
124
-		$model = $this->crud['model'];
125
-		$values_to_store = $this->compactFakeFields(\Request::all());
126
-		$item = $model::create($values_to_store);
127
-
128
-		// if it's a relationship with a pivot table, also sync that
129
-		$this->prepareFields();
130
-		foreach ($this->crud['fields'] as $k => $field) {
131
-			if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name']))
132
-			{
133
-				$model::find($item->id)->$field['name']()->attach(\Request::input($field['name']));
134
-			}
135
-		}
136
-
137
-		// show a success message
138
-		\Alert::success(trans('backpack::crud.insert_success'))->flash();
139
-
140
-		// redirect the user where he chose to be redirected
141
-		switch (\Request::input('redirect_after_save')) {
142
-			case 'current_item_edit':
143
-				return \Redirect::to($this->crud['route'].'/'.$item->id.'/edit');
144
-				break;
145
-
146
-			default:
147
-				return \Redirect::to(\Request::input('redirect_after_save'));
148
-				break;
149
-		}
150
-	}
151
-
152
-
153
-	/**
154
-	 * Show the form for editing the specified resource.
155
-	 *
156
-	 * @param  int  $id
157
-	 * @return Response
158
-	 */
159
-	public function edit($id)
160
-	{
161
-		// SECURITY:
162
-		// if edit_permission is false, abort
163
-		if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) {
164
-			abort(403, 'Not allowed.');
165
-		}
166
-
167
-		// get the info for that entry
168
-		$model = $this->crud['model'];
169
-		$this->data['entry'] = $model::find($id);
170
-		$this->data['entry']->addFakes($this->getFakeColumnsAsArray());
171
-
172
-		if (isset($this->data['crud']['update_fields']))
173
-		{
174
-			$this->crud['fields'] = $this->data['crud']['update_fields'];
175
-		}
176
-
177
-		// prepare the fields you need to show and prepopulate the values
178
-		$this->prepareFields($this->data['entry']);
179
-		$this->data['crud'] = $this->crud;
180
-		$this->data['title'] = trans('backpack::crud.edit').' '.$this->crud['entity_name'];
181
-
182
-		// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
183
-		return view('crud::edit', $this->data);
184
-	}
185
-
186
-
187
-	/**
188
-	 * Update the specified resource in the database.
189
-	 *
190
-	 * @param  int  $id
191
-	 * @return Response
192
-	 */
193
-	public function updateCrud(UpdateRequest $request = null)
194
-	{
195
-		// if edit_permission is false, abort
196
-		if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) {
197
-			abort(403, 'Not allowed.');
198
-		}
199
-
200
-		$model = $this->crud['model'];
201
-		$this->prepareFields($model::find(\Request::input('id')));
202
-
203
-		$item = $model::find(\Request::input('id'))
204
-						->update($this->compactFakeFields(\Request::all()));
205
-
206
-		// if it's a relationship with a pivot table, also sync that
207
-		foreach ($this->crud['fields'] as $k => $field) {
208
-			if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name']))
209
-			{
210
-				$model::find(\Request::input('id'))->$field['name']()->sync(\Request::input($field['name']));
211
-			}
212
-		}
213
-
214
-		// show a success message
215
-		\Alert::success(trans('backpack::crud.update_success'))->flash();
216
-
217
-		return \Redirect::to($this->crud['route']);
218
-	}
219
-
220
-
221
-	/**
222
-	 * Display the specified resource.
223
-	 *
224
-	 * @param  int  $id
225
-	 * @return Response
226
-	 */
227
-	public function show($id)
228
-	{
229
-		// get the info for that entry
230
-		$model = $this->crud['model'];
231
-		$this->data['entry'] = $model::find($id);
232
-		$this->data['entry']->addFakes($this->getFakeColumnsAsArray());
233
-		$this->data['crud'] = $this->crud;
234
-		$this->data['title'] = trans('backpack::crud.preview').' '.$this->crud['entity_name'];
235
-
236
-		// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
237
-		return view('crud::show', $this->data);
238
-	}
239
-
240
-
241
-	/**
242
-	 * Remove the specified resource from storage.
243
-	 *
244
-	 * @param  int  $id
245
-	 * @return Response
246
-	 */
247
-	public function destroy($id)
248
-	{
249
-		// SECURITY:
250
-		// if delete_permission is false, abort
251
-		if (isset($this->crud['delete_permission']) && !$this->crud['delete_permission']) {
252
-			abort(403, trans('backpack::crud.unauthorized_access'));
253
-		}
254
-
255
-		$model = $this->crud['model'];
256
-		$item = $model::find($id);
257
-		$item->delete();
258
-
259
-		return 'true';
260
-	}
261
-
262
-
263
-	/**
264
-	 *  Reorder the items in the database using the Nested Set pattern.
265
-	 *
266
-	 *	Database columns needed: id, parent_id, lft, rgt, depth, name/title
267
-	 *
268
-	 *  @return Response
269
-	 */
270
-	public function reorder($lang = false)
271
-	{
272
-		// if reorder_table_permission is false, abort
273
-		if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) {
274
-			abort(403, 'Not allowed.');
275
-		}
276
-
277
-		if ($lang == false)
278
-		{
279
-			$lang = \Lang::locale();
280
-		}
281
-
282
-		// get all results for that entity
283
-		$model = $this->crud['model'];
284
-		if (property_exists($model, 'translatable'))
285
-		{
286
-			$this->data['entries'] = $model::where('translation_lang', $lang)->get();
287
-			$this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all();
288
-			$this->data['active_language'] = $lang;
289
-		}
290
-		else
291
-		{
292
-			$this->data['entries'] = $model::all();
293
-		}
294
-		$this->data['crud'] = $this->crud;
295
-		$this->data['title'] = trans('backpack::crud.reorder').' '.$this->crud['entity_name'];
296
-
297
-		// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
298
-		return view('crud::reorder', $this->data);
299
-	}
300
-
301
-
302
-	/**
303
-	 * Save the new order, using the Nested Set pattern.
304
-	 *
305
-	 * Database columns needed: id, parent_id, lft, rgt, depth, name/title
306
-	 *
307
-	 * @return
308
-	 */
309
-	public function saveReorder()
310
-	{
311
-		// if reorder_table_permission is false, abort
312
-		if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) {
313
-			abort(403, 'Not allowed.');
314
-		}
315
-
316
-		$model = $this->crud['model'];
317
-		$count = 0;
318
-		$all_entries = \Request::input('tree');
319
-
320
-		if (count($all_entries)) {
321
-			foreach ($all_entries as $key => $entry) {
322
-				if ($entry['item_id'] != "" && $entry['item_id'] != null) {
323
-					$item = $model::find($entry['item_id']);
324
-					$item->parent_id = $entry['parent_id'];
325
-					$item->depth = $entry['depth'];
326
-					$item->lft = $entry['left'];
327
-					$item->rgt = $entry['right'];
328
-					$item->save();
329
-
330
-					$count++;
331
-				}
332
-			}
333
-		}
334
-		else
335
-		{
336
-			return false;
337
-		}
338
-
339
-		return 'success for '.$count." items";
340
-	}
341
-
342
-
343
-	/**
344
-	 * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table.
345
-	 * It defaults to showing all connected translations and their CRUD buttons.
346
-	 *
347
-	 * It's enabled by:
348
-	 * - setting the $crud['details_row'] variable to true;
349
-	 * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow');
350
-	 */
351
-	public function showDetailsRow($id)
352
-	{
353
-		// get the info for that entry
354
-		$model = $this->crud['model'];
355
-		$this->data['entry'] = $model::find($id);
356
-		$this->data['entry']->addFakes($this->getFakeColumnsAsArray());
357
-		$this->data['original_entry'] = $this->data['entry'];
358
-		$this->data['crud'] = $this->crud;
359
-
360
-		if (property_exists($model, 'translatable'))
361
-		{
362
-			$this->data['translations'] = $this->data['entry']->translations();
363
-
364
-			// create a list of languages the item is not translated in
365
-			$this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all();
366
-			$this->data['languages_already_translated_in'] = $this->data['entry']->translationLanguages();
367
-			$this->data['languages_to_translate_in'] = $this->data['languages']->diff($this->data['languages_already_translated_in']);
368
-			$this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function ($item) {
369
-			    return $item->abbr == \Lang::locale();
370
-			});
371
-		}
372
-
373
-		// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
374
-		return view('crud::details_row', $this->data);
375
-	}
376
-
377
-
378
-	/**
379
-	 * Duplicate an existing item into another language and open it for editing.
380
-	 */
381
-	public function translateItem($id, $lang)
382
-	{
383
-		$model = $this->crud['model'];
384
-		$this->data['entry'] = $model::find($id);
385
-		// check if there isn't a translation already
386
-		$existing_translation = $this->data['entry']->translation($lang);
387
-
388
-		if ($existing_translation)
389
-		{
390
-			$new_entry = $existing_translation;
391
-		}
392
-		else
393
-		{
394
-			// get the info for that entry
395
-			$new_entry_attributes = $this->data['entry']->getAttributes();
396
-			$new_entry_attributes['translation_lang'] = $lang;
397
-			$new_entry_attributes['translation_of'] = $id;
398
-			$new_entry_attributes = array_except($new_entry_attributes, 'id');
399
-
400
-			$new_entry = $model::create($new_entry_attributes);
401
-		}
402
-
403
-		// redirect to the edit form for that translation
404
-		return redirect(str_replace($id, $new_entry->id, str_replace('translate/'.$lang, 'edit', \Request::url())));
405
-	}
406
-
407
-
408
-
409
-	/**
410
-	 * COMMODITY FUNCTIONS
411
-	 */
412
-
413
-
414
-	/**
415
-	 * Refactor the request array to something that can be passed to the model's create or update function.
416
-	 * The resulting array will only include the fields that are stored in the database and their values,
417
-	 * plus the '_token' and 'redirect_after_save' variables.
418
-	 *
419
-	 * @param 	Request 	$request - everything that was sent from the form, usually \Request::all()
420
-	 * @return 	array
421
-	 */
422
-	protected function compactFakeFields($request) {
423
-
424
-		$this->prepareFields();
425
-
426
-		$fake_field_columns_to_encode = [];
427
-
428
-		// go through each defined field
429
-		foreach ($this->crud['fields'] as $k => $field) {
430
-			// if it's a fake field
431
-			if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) {
432
-				// add it to the request in its appropriate variable - the one defined, if defined
433
-				if (isset($this->crud['fields'][$k]['store_in'])) {
434
-					$request[$this->crud['fields'][$k]['store_in']][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']];
435
-
436
-					$remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']);
437
-					if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){
438
-				        array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']);
439
-				    }
440
-				}
441
-				else //otherwise in the one defined in the $crud variable
442
-				{
443
-					$request['extras'][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']];
444
-
445
-					$remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']);
446
-					if(!in_array('extras', $fake_field_columns_to_encode, true)){
447
-				        array_push($fake_field_columns_to_encode, 'extras');
448
-				    }
449
-				}
450
-			}
451
-		}
452
-
453
-		// json_encode all fake_value columns in the database, so they can be properly stored and interpreted
454
-		if (count($fake_field_columns_to_encode)) {
455
-			foreach ($fake_field_columns_to_encode as $key => $value) {
456
-				$request[$value] = json_encode($request[$value]);
457
-			}
458
-		}
459
-
460
-		// if there are no fake fields defined, this will just return the original Request in full
461
-		// since no modifications or additions have been made to $request
462
-		return $request;
463
-	}
464
-
465
-
466
-	/**
467
-	 * Returns an array of database columns names, that are used to store fake values.
468
-	 * Returns ['extras'] if no columns have been found.
469
-	 *
470
-	 */
471
-	protected function getFakeColumnsAsArray() {
472
-
473
-		$this->prepareFields();
474
-
475
-		$fake_field_columns_to_encode = [];
476
-
477
-		foreach ($this->crud['fields'] as $k => $field) {
478
-			// if it's a fake field
479
-			if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) {
480
-				// add it to the request in its appropriate variable - the one defined, if defined
481
-				if (isset($this->crud['fields'][$k]['store_in'])) {
482
-					if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){
483
-				        array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']);
484
-				    }
485
-				}
486
-				else //otherwise in the one defined in the $crud variable
487
-				{
488
-					if(!in_array('extras', $fake_field_columns_to_encode, true)){
489
-				        array_push($fake_field_columns_to_encode, 'extras');
490
-				    }
491
-				}
492
-			}
493
-		}
494
-
495
-		if (!count($fake_field_columns_to_encode)) {
496
-			return ['extras'];
497
-		}
498
-
499
-		return $fake_field_columns_to_encode;
500
-	}
501
-
502
-
503
-	// If it's not an array of array and it's a simple array, create a proper array of arrays for it
504
-	protected function prepareColumns()
505
-	{
506
-		// if the columns aren't set, we can't show this page
507
-		// TODO: instead of dying, show the columns defined as visible on the model
508
-		if (!isset($this->crud['columns']))
509
-		{
510
-			abort(500, "CRUD columns are not defined.");
511
-		}
512
-
513
-		// if the columns are defined as a string, transform it to a proper array
514
-		if (!is_array($this->crud['columns']))
515
-		{
516
-			$current_columns_array = explode(",", $this->crud['columns']);
517
-			$proper_columns_array = array();
518
-
519
-			foreach ($current_columns_array as $key => $col) {
520
-				$proper_columns_array[] = [
521
-								'name' => $col,
522
-								'label' => ucfirst($col) //TODO: also replace _ with space
523
-							];
524
-			}
525
-
526
-			$this->crud['columns'] = $proper_columns_array;
527
-		}
528
-	}
529
-
530
-	/**
531
-	 * Prepare the fields to be shown, stored, updated or created.
532
-	 *
533
-	 * Makes sure $this->crud['fields'] is in the proper format (array of arrays);
534
-	 * Makes sure $this->crud['fields'] also contains the id of the current item;
535
-	 * Makes sure $this->crud['fields'] also contains the values for each field;
536
-	 *
537
-	 */
538
-	protected function prepareFields($entry = false)
539
-	{
540
-		// if the fields have been defined separately for create and update, use that
541
-		if (!isset($this->crud['fields']))
542
-		{
543
-			if (isset($this->crud['create_fields']))
544
-			{
545
-				$this->crud['fields'] = $this->crud['create_fields'];
546
-			}
547
-			elseif (isset($this->crud['update_fields']))
548
-			{
549
-				$this->crud['fields'] = $this->crud['update_fields'];
550
-			}
551
-		}
552
-
553
-		// PREREQUISITES CHECK:
554
-		// if the fields aren't set, trigger error
555
-		if (!isset($this->crud['fields']))
556
-		{
557
-			abort(500, "The CRUD fields are not defined.");
558
-		}
559
-
560
-		// if the fields are defined as a string, transform it to a proper array
561
-		if (!is_array($this->crud['fields']))
562
-		{
563
-			$current_fields_array = explode(",", $this->crud['fields']);
564
-			$proper_fields_array = array();
565
-
566
-			foreach ($current_fields_array as $key => $field) {
567
-				$proper_fields_array[] = [
568
-								'name' => $field,
569
-								'label' => ucfirst($field), // TODO: also replace _ with space
570
-								'type' => 'text' // TODO: choose different types of fields depending on the MySQL column type
571
-							];
572
-			}
573
-
574
-			$this->crud['fields'] = $proper_fields_array;
575
-		}
576
-
577
-		// if no field type is defined, assume the "text" field type
578
-		foreach ($this->crud['fields'] as $k => $field) {
579
-				if (!isset($this->crud['fields'][$k]['type']))
580
-					$this->crud['fields'][$k]['type'] = 'text';
581
-			}
582
-
583
-		// if an entry was passed, we're preparing for the update form, not create
584
-		if ($entry) {
585
-			// put the values in the same 'fields' variable
586
-			$fields = $this->crud['fields'];
587
-
588
-			foreach ($fields as $k => $field) {
589
-				// set the value
590
-				if (!isset($this->crud['fields'][$k]['value']))
591
-				{
592
-					$this->crud['fields'][$k]['value'] = $entry->$field['name'];
593
-				}
594
-			}
595
-
596
-			// always have a hidden input for the entry id
597
-			$this->crud['fields'][] = array(
598
-												'name' => 'id',
599
-												'value' => $entry->id,
600
-												'type' => 'hidden'
601
-											);
602
-		}
603
-	}
17
+    use DispatchesJobs, ValidatesRequests;
18
+
19
+    public $data = array();
20
+    public $crud = array(
21
+                        "model" => "\App\Models\Entity",
22
+                        "entity_name" => "entry",
23
+                        "entity_name_plural" => "entries",
24
+                        "view_table_permission" => true,
25
+                        "add_permission" => true,
26
+                        "edit_permission" => true,
27
+                        "delete_permission" => true,
28
+                        "reorder_permission" => true,
29
+                        "reorder_max_level" => 3,
30
+                        "details_row" => false,
31
+                        );
32
+
33
+    public function __construct()
34
+    {
35
+        $this->data['crud'] = $this->crud;
36
+
37
+        // Check for the right roles to access these pages
38
+        // if (!\Entrust::can('view-admin-panel')) {
39
+        //        abort(403, trans('backpack::crud.unauthorized_access'));
40
+        //    }
41
+    }
42
+
43
+    /**
44
+     * Display all rows in the database for this entity.
45
+     *
46
+     * @return Response
47
+     */
48
+    public function index()
49
+    {
50
+        // SECURITY:
51
+        // if view_table_permission is false, abort
52
+        if (isset($this->crud['view_table_permission']) && !$this->crud['view_table_permission']) {
53
+            abort(403, 'Not allowed.');
54
+        }
55
+
56
+        // get all results for that entity
57
+        $model = $this->crud['model'];
58
+        if (property_exists($model, 'translatable'))
59
+        {
60
+            $this->data['entries'] = $model::where('translation_lang', \Lang::locale())->get();
61
+        }
62
+        else
63
+        {
64
+            $this->data['entries'] = $model::all();
65
+        }
66
+
67
+            // add the fake fields for each entry
68
+            foreach ($this->data['entries'] as $key => $entry) {
69
+                $entry->addFakes($this->getFakeColumnsAsArray());
70
+            }
71
+
72
+        $this->prepareColumns();
73
+        $this->data['crud'] = $this->crud;
74
+        $this->data['title'] = ucfirst($this->crud['entity_name_plural']);
75
+
76
+        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
77
+        return view('crud::list', $this->data);
78
+    }
79
+
80
+
81
+    /**
82
+     * Show the form for creating inserting a new row.
83
+     *
84
+     * @return Response
85
+     */
86
+    public function create()
87
+    {
88
+        // SECURITY:
89
+        // if add_permission is false, abort
90
+        if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) {
91
+            abort(403, 'Not allowed.');
92
+        }
93
+
94
+        // get the fields you need to show
95
+        if (isset($this->data['crud']['create_fields']))
96
+        {
97
+            $this->crud['fields'] = $this->data['crud']['create_fields'];
98
+        }
99
+
100
+        // prepare the fields you need to show
101
+        $this->prepareFields();
102
+        $this->data['crud'] = $this->crud;
103
+        $this->data['title'] = trans('backpack::crud.add').' '.$this->crud['entity_name'];
104
+
105
+        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
106
+        return view('crud::create', $this->data);
107
+    }
108
+
109
+
110
+    /**
111
+     * Store a newly created resource in the database.
112
+     *
113
+     * @return Response
114
+     */
115
+    public function storeCrud(StoreRequest $request = null)
116
+    {
117
+        // SECURITY:
118
+        // if add_permission is false, abort
119
+        if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) {
120
+            abort(403, 'Not allowed.');
121
+        }
122
+
123
+        // compress the fake fields into one field
124
+        $model = $this->crud['model'];
125
+        $values_to_store = $this->compactFakeFields(\Request::all());
126
+        $item = $model::create($values_to_store);
127
+
128
+        // if it's a relationship with a pivot table, also sync that
129
+        $this->prepareFields();
130
+        foreach ($this->crud['fields'] as $k => $field) {
131
+            if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name']))
132
+            {
133
+                $model::find($item->id)->$field['name']()->attach(\Request::input($field['name']));
134
+            }
135
+        }
136
+
137
+        // show a success message
138
+        \Alert::success(trans('backpack::crud.insert_success'))->flash();
139
+
140
+        // redirect the user where he chose to be redirected
141
+        switch (\Request::input('redirect_after_save')) {
142
+            case 'current_item_edit':
143
+                return \Redirect::to($this->crud['route'].'/'.$item->id.'/edit');
144
+                break;
145
+
146
+            default:
147
+                return \Redirect::to(\Request::input('redirect_after_save'));
148
+                break;
149
+        }
150
+    }
151
+
152
+
153
+    /**
154
+     * Show the form for editing the specified resource.
155
+     *
156
+     * @param  int  $id
157
+     * @return Response
158
+     */
159
+    public function edit($id)
160
+    {
161
+        // SECURITY:
162
+        // if edit_permission is false, abort
163
+        if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) {
164
+            abort(403, 'Not allowed.');
165
+        }
166
+
167
+        // get the info for that entry
168
+        $model = $this->crud['model'];
169
+        $this->data['entry'] = $model::find($id);
170
+        $this->data['entry']->addFakes($this->getFakeColumnsAsArray());
171
+
172
+        if (isset($this->data['crud']['update_fields']))
173
+        {
174
+            $this->crud['fields'] = $this->data['crud']['update_fields'];
175
+        }
176
+
177
+        // prepare the fields you need to show and prepopulate the values
178
+        $this->prepareFields($this->data['entry']);
179
+        $this->data['crud'] = $this->crud;
180
+        $this->data['title'] = trans('backpack::crud.edit').' '.$this->crud['entity_name'];
181
+
182
+        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
183
+        return view('crud::edit', $this->data);
184
+    }
185
+
186
+
187
+    /**
188
+     * Update the specified resource in the database.
189
+     *
190
+     * @param  int  $id
191
+     * @return Response
192
+     */
193
+    public function updateCrud(UpdateRequest $request = null)
194
+    {
195
+        // if edit_permission is false, abort
196
+        if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) {
197
+            abort(403, 'Not allowed.');
198
+        }
199
+
200
+        $model = $this->crud['model'];
201
+        $this->prepareFields($model::find(\Request::input('id')));
202
+
203
+        $item = $model::find(\Request::input('id'))
204
+                        ->update($this->compactFakeFields(\Request::all()));
205
+
206
+        // if it's a relationship with a pivot table, also sync that
207
+        foreach ($this->crud['fields'] as $k => $field) {
208
+            if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name']))
209
+            {
210
+                $model::find(\Request::input('id'))->$field['name']()->sync(\Request::input($field['name']));
211
+            }
212
+        }
213
+
214
+        // show a success message
215
+        \Alert::success(trans('backpack::crud.update_success'))->flash();
216
+
217
+        return \Redirect::to($this->crud['route']);
218
+    }
219
+
220
+
221
+    /**
222
+     * Display the specified resource.
223
+     *
224
+     * @param  int  $id
225
+     * @return Response
226
+     */
227
+    public function show($id)
228
+    {
229
+        // get the info for that entry
230
+        $model = $this->crud['model'];
231
+        $this->data['entry'] = $model::find($id);
232
+        $this->data['entry']->addFakes($this->getFakeColumnsAsArray());
233
+        $this->data['crud'] = $this->crud;
234
+        $this->data['title'] = trans('backpack::crud.preview').' '.$this->crud['entity_name'];
235
+
236
+        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
237
+        return view('crud::show', $this->data);
238
+    }
239
+
240
+
241
+    /**
242
+     * Remove the specified resource from storage.
243
+     *
244
+     * @param  int  $id
245
+     * @return Response
246
+     */
247
+    public function destroy($id)
248
+    {
249
+        // SECURITY:
250
+        // if delete_permission is false, abort
251
+        if (isset($this->crud['delete_permission']) && !$this->crud['delete_permission']) {
252
+            abort(403, trans('backpack::crud.unauthorized_access'));
253
+        }
254
+
255
+        $model = $this->crud['model'];
256
+        $item = $model::find($id);
257
+        $item->delete();
258
+
259
+        return 'true';
260
+    }
261
+
262
+
263
+    /**
264
+     *  Reorder the items in the database using the Nested Set pattern.
265
+     *
266
+     *	Database columns needed: id, parent_id, lft, rgt, depth, name/title
267
+     *
268
+     *  @return Response
269
+     */
270
+    public function reorder($lang = false)
271
+    {
272
+        // if reorder_table_permission is false, abort
273
+        if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) {
274
+            abort(403, 'Not allowed.');
275
+        }
276
+
277
+        if ($lang == false)
278
+        {
279
+            $lang = \Lang::locale();
280
+        }
281
+
282
+        // get all results for that entity
283
+        $model = $this->crud['model'];
284
+        if (property_exists($model, 'translatable'))
285
+        {
286
+            $this->data['entries'] = $model::where('translation_lang', $lang)->get();
287
+            $this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all();
288
+            $this->data['active_language'] = $lang;
289
+        }
290
+        else
291
+        {
292
+            $this->data['entries'] = $model::all();
293
+        }
294
+        $this->data['crud'] = $this->crud;
295
+        $this->data['title'] = trans('backpack::crud.reorder').' '.$this->crud['entity_name'];
296
+
297
+        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
298
+        return view('crud::reorder', $this->data);
299
+    }
300
+
301
+
302
+    /**
303
+     * Save the new order, using the Nested Set pattern.
304
+     *
305
+     * Database columns needed: id, parent_id, lft, rgt, depth, name/title
306
+     *
307
+     * @return
308
+     */
309
+    public function saveReorder()
310
+    {
311
+        // if reorder_table_permission is false, abort
312
+        if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) {
313
+            abort(403, 'Not allowed.');
314
+        }
315
+
316
+        $model = $this->crud['model'];
317
+        $count = 0;
318
+        $all_entries = \Request::input('tree');
319
+
320
+        if (count($all_entries)) {
321
+            foreach ($all_entries as $key => $entry) {
322
+                if ($entry['item_id'] != "" && $entry['item_id'] != null) {
323
+                    $item = $model::find($entry['item_id']);
324
+                    $item->parent_id = $entry['parent_id'];
325
+                    $item->depth = $entry['depth'];
326
+                    $item->lft = $entry['left'];
327
+                    $item->rgt = $entry['right'];
328
+                    $item->save();
329
+
330
+                    $count++;
331
+                }
332
+            }
333
+        }
334
+        else
335
+        {
336
+            return false;
337
+        }
338
+
339
+        return 'success for '.$count." items";
340
+    }
341
+
342
+
343
+    /**
344
+     * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table.
345
+     * It defaults to showing all connected translations and their CRUD buttons.
346
+     *
347
+     * It's enabled by:
348
+     * - setting the $crud['details_row'] variable to true;
349
+     * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow');
350
+     */
351
+    public function showDetailsRow($id)
352
+    {
353
+        // get the info for that entry
354
+        $model = $this->crud['model'];
355
+        $this->data['entry'] = $model::find($id);
356
+        $this->data['entry']->addFakes($this->getFakeColumnsAsArray());
357
+        $this->data['original_entry'] = $this->data['entry'];
358
+        $this->data['crud'] = $this->crud;
359
+
360
+        if (property_exists($model, 'translatable'))
361
+        {
362
+            $this->data['translations'] = $this->data['entry']->translations();
363
+
364
+            // create a list of languages the item is not translated in
365
+            $this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all();
366
+            $this->data['languages_already_translated_in'] = $this->data['entry']->translationLanguages();
367
+            $this->data['languages_to_translate_in'] = $this->data['languages']->diff($this->data['languages_already_translated_in']);
368
+            $this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function ($item) {
369
+                return $item->abbr == \Lang::locale();
370
+            });
371
+        }
372
+
373
+        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
374
+        return view('crud::details_row', $this->data);
375
+    }
376
+
377
+
378
+    /**
379
+     * Duplicate an existing item into another language and open it for editing.
380
+     */
381
+    public function translateItem($id, $lang)
382
+    {
383
+        $model = $this->crud['model'];
384
+        $this->data['entry'] = $model::find($id);
385
+        // check if there isn't a translation already
386
+        $existing_translation = $this->data['entry']->translation($lang);
387
+
388
+        if ($existing_translation)
389
+        {
390
+            $new_entry = $existing_translation;
391
+        }
392
+        else
393
+        {
394
+            // get the info for that entry
395
+            $new_entry_attributes = $this->data['entry']->getAttributes();
396
+            $new_entry_attributes['translation_lang'] = $lang;
397
+            $new_entry_attributes['translation_of'] = $id;
398
+            $new_entry_attributes = array_except($new_entry_attributes, 'id');
399
+
400
+            $new_entry = $model::create($new_entry_attributes);
401
+        }
402
+
403
+        // redirect to the edit form for that translation
404
+        return redirect(str_replace($id, $new_entry->id, str_replace('translate/'.$lang, 'edit', \Request::url())));
405
+    }
406
+
407
+
408
+
409
+    /**
410
+     * COMMODITY FUNCTIONS
411
+     */
412
+
413
+
414
+    /**
415
+     * Refactor the request array to something that can be passed to the model's create or update function.
416
+     * The resulting array will only include the fields that are stored in the database and their values,
417
+     * plus the '_token' and 'redirect_after_save' variables.
418
+     *
419
+     * @param 	Request 	$request - everything that was sent from the form, usually \Request::all()
420
+     * @return 	array
421
+     */
422
+    protected function compactFakeFields($request) {
423
+
424
+        $this->prepareFields();
425
+
426
+        $fake_field_columns_to_encode = [];
427
+
428
+        // go through each defined field
429
+        foreach ($this->crud['fields'] as $k => $field) {
430
+            // if it's a fake field
431
+            if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) {
432
+                // add it to the request in its appropriate variable - the one defined, if defined
433
+                if (isset($this->crud['fields'][$k]['store_in'])) {
434
+                    $request[$this->crud['fields'][$k]['store_in']][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']];
435
+
436
+                    $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']);
437
+                    if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){
438
+                        array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']);
439
+                    }
440
+                }
441
+                else //otherwise in the one defined in the $crud variable
442
+                {
443
+                    $request['extras'][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']];
444
+
445
+                    $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']);
446
+                    if(!in_array('extras', $fake_field_columns_to_encode, true)){
447
+                        array_push($fake_field_columns_to_encode, 'extras');
448
+                    }
449
+                }
450
+            }
451
+        }
452
+
453
+        // json_encode all fake_value columns in the database, so they can be properly stored and interpreted
454
+        if (count($fake_field_columns_to_encode)) {
455
+            foreach ($fake_field_columns_to_encode as $key => $value) {
456
+                $request[$value] = json_encode($request[$value]);
457
+            }
458
+        }
459
+
460
+        // if there are no fake fields defined, this will just return the original Request in full
461
+        // since no modifications or additions have been made to $request
462
+        return $request;
463
+    }
464
+
465
+
466
+    /**
467
+     * Returns an array of database columns names, that are used to store fake values.
468
+     * Returns ['extras'] if no columns have been found.
469
+     *
470
+     */
471
+    protected function getFakeColumnsAsArray() {
472
+
473
+        $this->prepareFields();
474
+
475
+        $fake_field_columns_to_encode = [];
476
+
477
+        foreach ($this->crud['fields'] as $k => $field) {
478
+            // if it's a fake field
479
+            if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) {
480
+                // add it to the request in its appropriate variable - the one defined, if defined
481
+                if (isset($this->crud['fields'][$k]['store_in'])) {
482
+                    if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){
483
+                        array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']);
484
+                    }
485
+                }
486
+                else //otherwise in the one defined in the $crud variable
487
+                {
488
+                    if(!in_array('extras', $fake_field_columns_to_encode, true)){
489
+                        array_push($fake_field_columns_to_encode, 'extras');
490
+                    }
491
+                }
492
+            }
493
+        }
494
+
495
+        if (!count($fake_field_columns_to_encode)) {
496
+            return ['extras'];
497
+        }
498
+
499
+        return $fake_field_columns_to_encode;
500
+    }
501
+
502
+
503
+    // If it's not an array of array and it's a simple array, create a proper array of arrays for it
504
+    protected function prepareColumns()
505
+    {
506
+        // if the columns aren't set, we can't show this page
507
+        // TODO: instead of dying, show the columns defined as visible on the model
508
+        if (!isset($this->crud['columns']))
509
+        {
510
+            abort(500, "CRUD columns are not defined.");
511
+        }
512
+
513
+        // if the columns are defined as a string, transform it to a proper array
514
+        if (!is_array($this->crud['columns']))
515
+        {
516
+            $current_columns_array = explode(",", $this->crud['columns']);
517
+            $proper_columns_array = array();
518
+
519
+            foreach ($current_columns_array as $key => $col) {
520
+                $proper_columns_array[] = [
521
+                                'name' => $col,
522
+                                'label' => ucfirst($col) //TODO: also replace _ with space
523
+                            ];
524
+            }
525
+
526
+            $this->crud['columns'] = $proper_columns_array;
527
+        }
528
+    }
529
+
530
+    /**
531
+     * Prepare the fields to be shown, stored, updated or created.
532
+     *
533
+     * Makes sure $this->crud['fields'] is in the proper format (array of arrays);
534
+     * Makes sure $this->crud['fields'] also contains the id of the current item;
535
+     * Makes sure $this->crud['fields'] also contains the values for each field;
536
+     *
537
+     */
538
+    protected function prepareFields($entry = false)
539
+    {
540
+        // if the fields have been defined separately for create and update, use that
541
+        if (!isset($this->crud['fields']))
542
+        {
543
+            if (isset($this->crud['create_fields']))
544
+            {
545
+                $this->crud['fields'] = $this->crud['create_fields'];
546
+            }
547
+            elseif (isset($this->crud['update_fields']))
548
+            {
549
+                $this->crud['fields'] = $this->crud['update_fields'];
550
+            }
551
+        }
552
+
553
+        // PREREQUISITES CHECK:
554
+        // if the fields aren't set, trigger error
555
+        if (!isset($this->crud['fields']))
556
+        {
557
+            abort(500, "The CRUD fields are not defined.");
558
+        }
559
+
560
+        // if the fields are defined as a string, transform it to a proper array
561
+        if (!is_array($this->crud['fields']))
562
+        {
563
+            $current_fields_array = explode(",", $this->crud['fields']);
564
+            $proper_fields_array = array();
565
+
566
+            foreach ($current_fields_array as $key => $field) {
567
+                $proper_fields_array[] = [
568
+                                'name' => $field,
569
+                                'label' => ucfirst($field), // TODO: also replace _ with space
570
+                                'type' => 'text' // TODO: choose different types of fields depending on the MySQL column type
571
+                            ];
572
+            }
573
+
574
+            $this->crud['fields'] = $proper_fields_array;
575
+        }
576
+
577
+        // if no field type is defined, assume the "text" field type
578
+        foreach ($this->crud['fields'] as $k => $field) {
579
+                if (!isset($this->crud['fields'][$k]['type']))
580
+                    $this->crud['fields'][$k]['type'] = 'text';
581
+            }
582
+
583
+        // if an entry was passed, we're preparing for the update form, not create
584
+        if ($entry) {
585
+            // put the values in the same 'fields' variable
586
+            $fields = $this->crud['fields'];
587
+
588
+            foreach ($fields as $k => $field) {
589
+                // set the value
590
+                if (!isset($this->crud['fields'][$k]['value']))
591
+                {
592
+                    $this->crud['fields'][$k]['value'] = $entry->$field['name'];
593
+                }
594
+            }
595
+
596
+            // always have a hidden input for the entry id
597
+            $this->crud['fields'][] = array(
598
+                                                'name' => 'id',
599
+                                                'value' => $entry->id,
600
+                                                'type' => 'hidden'
601
+                                            );
602
+        }
603
+    }
604 604
 
605 605
 }
Please login to merge, or discard this patch.
src/app/Http/Requests/CrudRequest.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -4,30 +4,30 @@
 block discarded – undo
4 4
 
5 5
 class CrudRequest extends FormRequest {
6 6
 
7
-	/**
8
-	 * Determine if the user is authorized to make this request.
9
-	 *
10
-	 * @return bool
11
-	 */
12
-	public function authorize()
13
-	{
14
-		// only allow creates if the user is logged in
15
-		return \Auth::check();
16
-	}
7
+    /**
8
+     * Determine if the user is authorized to make this request.
9
+     *
10
+     * @return bool
11
+     */
12
+    public function authorize()
13
+    {
14
+        // only allow creates if the user is logged in
15
+        return \Auth::check();
16
+    }
17 17
 
18
-	/**
19
-	 * Get the validation rules that apply to the request.
20
-	 *
21
-	 * @return array
22
-	 */
23
-	public function rules()
24
-	{
25
-		return [
26
-			// 'name' => 'required|min:3|max:255'
27
-		];
28
-	}
18
+    /**
19
+     * Get the validation rules that apply to the request.
20
+     *
21
+     * @return array
22
+     */
23
+    public function rules()
24
+    {
25
+        return [
26
+            // 'name' => 'required|min:3|max:255'
27
+        ];
28
+    }
29 29
 
30
-	// OPTIONAL OVERRIDE
30
+    // OPTIONAL OVERRIDE
31 31
     // public function forbiddenResponse()
32 32
     // {
33 33
         // Optionally, send a custom response on authorize failure
Please login to merge, or discard this patch.
src/resources/views/form_content.blade.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@
 block discarded – undo
25 25
 {{-- For each form type, load its assets, if needed --}}
26 26
 {{-- But only once per field type (no need to include the same css/js files multiple times on the same page) --}}
27 27
 <?php
28
-	$loaded_form_types_css = array();
29
-	$loaded_form_types_js = array();
28
+    $loaded_form_types_css = array();
29
+    $loaded_form_types_js = array();
30 30
 ?>
31 31
 
32 32
 @section('after_styles')
Please login to merge, or discard this patch.
src/resources/views/list.blade.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -71,24 +71,24 @@
 block discarded – undo
71 71
                             if ($results && $results->count()) {
72 72
                                 $results_array = $results->lists($column['attribute'], 'id');
73 73
                                 echo implode(', ', $results_array->toArray());
74
-                              }
75
-                              else
76
-                              {
74
+                                }
75
+                                else
76
+                                {
77 77
                                 echo '-';
78
-                              }
79
-                             ?></td>
78
+                                }
79
+                                ?></td>
80 80
                           @elseif (isset($column['type']) && $column['type']=='select')
81 81
                             {{-- single relationships (1-1, 1-n) --}}
82 82
                             <td><?php
83 83
                             if ($entry->{$column['entity']}()->getResults()) {
84 84
                                 echo $entry->{$column['entity']}()->getResults()->{$column['attribute']};
85
-                              }
86
-                             ?></td>
85
+                                }
86
+                                ?></td>
87 87
                           @elseif (isset($column['type']) && $column['type']=='model_function')
88 88
                             {{-- custom return value --}}
89 89
                             <td><?php
90 90
                                 echo $entry->{$column['function_name']}();
91
-                             ?></td>
91
+                                ?></td>
92 92
                           @else
93 93
                             {{-- regular object attribute --}}
94 94
                             <td>{{ str_limit(strip_tags($entry->$column['name']), 80, "[...]") }}</td>
Please login to merge, or discard this patch.
src/resources/views/details_row.blade.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,23 +33,23 @@
 block discarded – undo
33 33
 				                      @if (isset($column['type']) && $column['type']=='select_multiple')
34 34
 				                        {{-- relationships with pivot table (n-n) --}}
35 35
 				                        <td><?php
36
-				                        $results = $entry->{$column['entity']}()->getResults();
37
-				                        if ($results && $results->count()) {
38
-				                            $results_array = $results->lists($column['attribute'], 'id');
39
-				                            echo implode(', ', $results_array->toArray());
40
-				                          }
41
-				                          else
42
-				                          {
43
-				                            echo '-';
44
-				                          }
45
-				                         ?></td>
36
+                                        $results = $entry->{$column['entity']}()->getResults();
37
+                                        if ($results && $results->count()) {
38
+                                            $results_array = $results->lists($column['attribute'], 'id');
39
+                                            echo implode(', ', $results_array->toArray());
40
+                                            }
41
+                                            else
42
+                                            {
43
+                                            echo '-';
44
+                                            }
45
+                                            ?></td>
46 46
 				                      @elseif (isset($column['type']) && $column['type']=='select')
47 47
 				                        {{-- single relationships (1-1, 1-n) --}}
48 48
 				                        <td><?php
49
-				                        if ($entry->{$column['entity']}()->getResults()) {
50
-				                            echo $entry->{$column['entity']}()->getResults()->{$column['attribute']};
51
-				                          }
52
-				                         ?></td>
49
+                                        if ($entry->{$column['entity']}()->getResults()) {
50
+                                            echo $entry->{$column['entity']}()->getResults()->{$column['attribute']};
51
+                                            }
52
+                                            ?></td>
53 53
 				                      @else
54 54
 				                        {{-- regular object attribute --}}
55 55
 				                        <td>{{ str_limit(strip_tags($entry->$column['name']), 80, "[...]") }}</td>
Please login to merge, or discard this patch.
src/resources/views/reorder.blade.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -20,42 +20,42 @@  discard block
 block discarded – undo
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 (!(isset($crud['view_table_permission']) && !$crud['view_table_permission']))
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/resources/lang/en/crud.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-	/*
5
+    /*
6 6
 	|--------------------------------------------------------------------------
7 7
 	| Dick Crud Language Lines
8 8
 	|--------------------------------------------------------------------------
@@ -13,77 +13,77 @@  discard block
 block discarded – undo
13 13
 	|
14 14
 	*/
15 15
 
16
-	// Create form
17
-	'add' 				=> 'Add',
18
-	'back_to_all'     	=> 'Back to all ',
19
-	'cancel'     		=> 'Cancel',
20
-	'add_a_new'     	=> 'Add a new ',
16
+    // Create form
17
+    'add' 				=> 'Add',
18
+    'back_to_all'     	=> 'Back to all ',
19
+    'cancel'     		=> 'Cancel',
20
+    'add_a_new'     	=> 'Add a new ',
21 21
 
22
-		// Create form - advanced options
23
-		'after_saving' => "After saving",
24
-		'go_to_the_table_view' => "go to the table view",
25
-		'let_me_add_another_item' => "let me add another item",
26
-		'edit_the_new_item' => "edit the new item",
22
+        // Create form - advanced options
23
+        'after_saving' => "After saving",
24
+        'go_to_the_table_view' => "go to the table view",
25
+        'let_me_add_another_item' => "let me add another item",
26
+        'edit_the_new_item' => "edit the new item",
27 27
 
28
-	// Edit form
29
-	'edit'     			=> 'Edit',
30
-	'save'     			=> 'Save',
28
+    // Edit form
29
+    'edit'     			=> 'Edit',
30
+    'save'     			=> 'Save',
31 31
 
32
-	// CRUD table view
33
-	'all'     			=> 'All ',
34
-	'in_the_database'   => 'in the database',
35
-	'list'     			=> 'List',
36
-	'actions'     		=> 'Actions',
37
-	'preview'     		=> 'Preview',
38
-	'delete'     		=> 'Delete',
32
+    // CRUD table view
33
+    'all'     			=> 'All ',
34
+    'in_the_database'   => 'in the database',
35
+    'list'     			=> 'List',
36
+    'actions'     		=> 'Actions',
37
+    'preview'     		=> 'Preview',
38
+    'delete'     		=> 'Delete',
39 39
 
40
-		// Confirmation messages and bubbles
41
-		'delete_confirm'     						=> 'Are you sure you want to delete this item?',
42
-		'delete_confirmation_title'     			=> 'Item Deleted',
43
-		'delete_confirmation_message'     			=> 'The item has been deleted successfully.',
44
-		'delete_confirmation_not_title'     		=> 'NOT deleted',
45
-		'delete_confirmation_not_message'     		=> "There's been an error. Your item might not have been deleted.",
46
-		'delete_confirmation_not_deleted_title'     => 'Not deleted',
47
-		'delete_confirmation_not_deleted_message'   => 'Nothing happened. Your item is safe.',
40
+        // Confirmation messages and bubbles
41
+        'delete_confirm'     						=> 'Are you sure you want to delete this item?',
42
+        'delete_confirmation_title'     			=> 'Item Deleted',
43
+        'delete_confirmation_message'     			=> 'The item has been deleted successfully.',
44
+        'delete_confirmation_not_title'     		=> 'NOT deleted',
45
+        'delete_confirmation_not_message'     		=> "There's been an error. Your item might not have been deleted.",
46
+        'delete_confirmation_not_deleted_title'     => 'Not deleted',
47
+        'delete_confirmation_not_deleted_message'   => 'Nothing happened. Your item is safe.',
48 48
 
49
-		// DataTables translation
50
-		"emptyTable" =>     "No data available in table",
51
-	    "info" =>           "Showing _START_ to _END_ of _TOTAL_ entries",
52
-	    "infoEmpty" =>      "Showing 0 to 0 of 0 entries",
53
-	    "infoFiltered" =>   "(filtered from _MAX_ total entries)",
54
-	    "infoPostFix" =>    "",
55
-	    "thousands" =>      ",",
56
-	    "lengthMenu" =>     "_MENU_ records per page",
57
-	    "loadingRecords" => "Loading...",
58
-	    "processing" =>     "Processing...",
59
-	    "search" =>         "Search: ",
60
-	    "zeroRecords" =>    "No matching records found",
61
-	    "paginate" => [
62
-	        "first" =>      "First",
63
-	        "last" =>       "Last",
64
-	        "next" =>       "Next",
65
-	        "previous" =>   "Previous"
66
-	    ],
67
-	    "aria" => [
68
-	        "sortAscending" =>  ": activate to sort column ascending",
69
-	        "sortDescending" => ": activate to sort column descending"
70
-	    ],
49
+        // DataTables translation
50
+        "emptyTable" =>     "No data available in table",
51
+        "info" =>           "Showing _START_ to _END_ of _TOTAL_ entries",
52
+        "infoEmpty" =>      "Showing 0 to 0 of 0 entries",
53
+        "infoFiltered" =>   "(filtered from _MAX_ total entries)",
54
+        "infoPostFix" =>    "",
55
+        "thousands" =>      ",",
56
+        "lengthMenu" =>     "_MENU_ records per page",
57
+        "loadingRecords" => "Loading...",
58
+        "processing" =>     "Processing...",
59
+        "search" =>         "Search: ",
60
+        "zeroRecords" =>    "No matching records found",
61
+        "paginate" => [
62
+            "first" =>      "First",
63
+            "last" =>       "Last",
64
+            "next" =>       "Next",
65
+            "previous" =>   "Previous"
66
+        ],
67
+        "aria" => [
68
+            "sortAscending" =>  ": activate to sort column ascending",
69
+            "sortDescending" => ": activate to sort column descending"
70
+        ],
71 71
 
72
-	// global crud - errors
73
-	"unauthorized_access" => "Unauthorized access - you do not have the necessary permissions to see this page.",
72
+    // global crud - errors
73
+    "unauthorized_access" => "Unauthorized access - you do not have the necessary permissions to see this page.",
74 74
 
75
-	// global crud - success / error notification bubbles
76
-	"insert_success" => "The item has been added successfully.",
77
-	"update_success" => "The item has been modified successfully.",
75
+    // global crud - success / error notification bubbles
76
+    "insert_success" => "The item has been added successfully.",
77
+    "update_success" => "The item has been modified successfully.",
78 78
 
79
-	// CRUD reorder view
80
-	'reorder'     				=> 'Reorder',
81
-	'reorder_text'     			=> 'Use drag&drop to reorder.',
82
-	'reorder_success_title'     => 'Done',
83
-	'reorder_success_message'   => 'Your order has been saved.',
84
-	'reorder_error_title'   	=> 'Error',
85
-	'reorder_error_message'   	=> 'Your order has not been saved.',
79
+    // CRUD reorder view
80
+    'reorder'     				=> 'Reorder',
81
+    'reorder_text'     			=> 'Use drag&drop to reorder.',
82
+    'reorder_success_title'     => 'Done',
83
+    'reorder_success_message'   => 'Your order has been saved.',
84
+    'reorder_error_title'   	=> 'Error',
85
+    'reorder_error_message'   	=> 'Your order has not been saved.',
86 86
 
87
-	'rules_text'	=> "<strong>Notice: </strong> Do not translate words prefixed with colon (ex: ':number_of_items'). Those will be replaced automatically with a proper value. If translated, that stops working.",
87
+    'rules_text'	=> "<strong>Notice: </strong> Do not translate words prefixed with colon (ex: ':number_of_items'). Those will be replaced automatically with a proper value. If translated, that stops working.",
88 88
 
89 89
 ];
Please login to merge, or discard this patch.
src/resources/lang/ro/crud.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-	/*
5
+    /*
6 6
 	|--------------------------------------------------------------------------
7 7
 	| Dick Crud Language Lines
8 8
 	|--------------------------------------------------------------------------
@@ -13,66 +13,66 @@  discard block
 block discarded – undo
13 13
 	|
14 14
 	*/
15 15
 
16
-	// Create form
17
-	'add' 				=> 'Adaugă',
18
-	'back_to_all'     	=> 'Înapoi la toate ',
19
-	'cancel'     		=> 'Anulează',
20
-	'add_a_new'     	=> 'Adaugă un nou ',
16
+    // Create form
17
+    'add' 				=> 'Adaugă',
18
+    'back_to_all'     	=> 'Înapoi la toate ',
19
+    'cancel'     		=> 'Anulează',
20
+    'add_a_new'     	=> 'Adaugă un nou ',
21 21
 
22
-		// Create form - advanced options
23
-		'after_saving' => "După salvare",
24
-		'go_to_the_table_view' => "du-mă la toate intrările",
25
-		'let_me_add_another_item' => "vreu să adaug o altă intrare",
26
-		'edit_the_new_item' => "vreau să editez intrarea",
22
+        // Create form - advanced options
23
+        'after_saving' => "După salvare",
24
+        'go_to_the_table_view' => "du-mă la toate intrările",
25
+        'let_me_add_another_item' => "vreu să adaug o altă intrare",
26
+        'edit_the_new_item' => "vreau să editez intrarea",
27 27
 
28
-	// Edit form
29
-	'edit'     			=> 'Editează',
30
-	'save'     			=> 'Salvează',
28
+    // Edit form
29
+    'edit'     			=> 'Editează',
30
+    'save'     			=> 'Salvează',
31 31
 
32
-	// CRUD table view
33
-	'all'     			=> 'Toate ',
34
-	'in_the_database'   => 'din baza de date',
35
-	'list'     			=> 'Listă',
36
-	'actions'     		=> 'Operațiuni',
37
-	'preview'     		=> 'Previzualizează',
38
-	'delete'     		=> 'Șterge',
32
+    // CRUD table view
33
+    'all'     			=> 'Toate ',
34
+    'in_the_database'   => 'din baza de date',
35
+    'list'     			=> 'Listă',
36
+    'actions'     		=> 'Operațiuni',
37
+    'preview'     		=> 'Previzualizează',
38
+    'delete'     		=> 'Șterge',
39 39
 
40
-		// Confirmation messages and bubbles
41
-		'delete_confirm'     						=> 'Ești sigur că vrei să ștergi această intrare?',
42
-		'delete_confirmation_title'     			=> 'Intrare ștearsă',
43
-		'delete_confirmation_message'     			=> 'Intrarea a fost ștearsă cu succes.',
44
-		'delete_confirmation_not_title'     		=> 'Eroare',
45
-		'delete_confirmation_not_message'     		=> "A avut loc o eroare. E posibil ca intrarea să nu fi fost ștearsă.",
46
-		'delete_confirmation_not_deleted_title'     => 'Intrarea nu a fost ștearsă',
47
-		'delete_confirmation_not_deleted_message'   => 'Nu am șters intrarea din baza de date.',
40
+        // Confirmation messages and bubbles
41
+        'delete_confirm'     						=> 'Ești sigur că vrei să ștergi această intrare?',
42
+        'delete_confirmation_title'     			=> 'Intrare ștearsă',
43
+        'delete_confirmation_message'     			=> 'Intrarea a fost ștearsă cu succes.',
44
+        'delete_confirmation_not_title'     		=> 'Eroare',
45
+        'delete_confirmation_not_message'     		=> "A avut loc o eroare. E posibil ca intrarea să nu fi fost ștearsă.",
46
+        'delete_confirmation_not_deleted_title'     => 'Intrarea nu a fost ștearsă',
47
+        'delete_confirmation_not_deleted_message'   => 'Nu am șters intrarea din baza de date.',
48 48
 
49
-		// DataTables translation
50
-		"emptyTable" =>     "Nu există intrări în baza de date",
51
-	    "info" =>           "Sunt afișate intrările _START_-_END_ din _TOTAL_",
52
-	    "infoEmpty" =>      "Sunt afișate toate intrarile. Adică niciuna.",
53
-	    "infoFiltered" =>   "(filtrate din _MAX_ intrări în total)",
54
-	    "infoPostFix" =>    "",
55
-	    "thousands" =>      ",",
56
-	    "lengthMenu" =>     "_MENU_ intrări pe pagină",
57
-	    "loadingRecords" => "Se încarcă...",
58
-	    "processing" =>     "Se procesează...",
59
-	    "search" =>         "Caută: ",
60
-	    "zeroRecords" =>    "Nu au fost găsite intrări care să se potrivească",
61
-	    "paginate" => [
62
-	        "first" =>      "Prima pagină",
63
-	        "last" =>       "Ultima pagină",
64
-	        "next" =>       "Pagina următoare",
65
-	        "previous" =>   "Pagina anterioară"
66
-	    ],
67
-	    "aria" => [
68
-	        "sortAscending" =>  ": activează pentru a ordona ascendent coloana",
69
-	        "sortDescending" => ": activează petnru a ordona descendent coloana"
70
-	    ],
49
+        // DataTables translation
50
+        "emptyTable" =>     "Nu există intrări în baza de date",
51
+        "info" =>           "Sunt afișate intrările _START_-_END_ din _TOTAL_",
52
+        "infoEmpty" =>      "Sunt afișate toate intrarile. Adică niciuna.",
53
+        "infoFiltered" =>   "(filtrate din _MAX_ intrări în total)",
54
+        "infoPostFix" =>    "",
55
+        "thousands" =>      ",",
56
+        "lengthMenu" =>     "_MENU_ intrări pe pagină",
57
+        "loadingRecords" => "Se încarcă...",
58
+        "processing" =>     "Se procesează...",
59
+        "search" =>         "Caută: ",
60
+        "zeroRecords" =>    "Nu au fost găsite intrări care să se potrivească",
61
+        "paginate" => [
62
+            "first" =>      "Prima pagină",
63
+            "last" =>       "Ultima pagină",
64
+            "next" =>       "Pagina următoare",
65
+            "previous" =>   "Pagina anterioară"
66
+        ],
67
+        "aria" => [
68
+            "sortAscending" =>  ": activează pentru a ordona ascendent coloana",
69
+            "sortDescending" => ": activează petnru a ordona descendent coloana"
70
+        ],
71 71
 
72
-	// global crud - errors
73
-	"unauthorized_access" => "Acces neautorizat - Nu ai permisiunea necesară pentru a accesa pagina.",
72
+    // global crud - errors
73
+    "unauthorized_access" => "Acces neautorizat - Nu ai permisiunea necesară pentru a accesa pagina.",
74 74
 
75
-	// global crud - success / error notification bubbles
76
-	"insert_success" => "Intrarea a fost adăugată cu succes.",
77
-	"update_success" => "Intrarea a fost modificată cu succes.",
75
+    // global crud - success / error notification bubbles
76
+    "insert_success" => "Intrarea a fost adăugată cu succes.",
77
+    "update_success" => "Intrarea a fost modificată cu succes.",
78 78
 ];
Please login to merge, or discard this patch.
src/CrudTrait.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
     |--------------------------------------------------------------------------
13 13
     */
14 14
 
15
-	public static function getPossibleEnumValues($field_name){
15
+    public static function getPossibleEnumValues($field_name){
16 16
         $instance = new static; // create an instance of the model to be able to get the table name
17 17
         $type = DB::select( DB::raw('SHOW COLUMNS FROM '.$instance->getTable().' WHERE Field = "'.$field_name.'"') )[0]->Type;
18 18
         preg_match('/^enum\((.*)\)$/', $type, $matches);
Please login to merge, or discard this patch.