VocabularyCrudController::setup()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 19
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Frontend\Vocabulary;
4
5
use App\Http\Requests\Frontend\Vocabulary\VocabularyRequest as StoreRequest;
6
use App\Http\Requests\Frontend\Vocabulary\VocabularyRequest as UpdateRequest;
7
// VALIDATION: change the requests to match your own file names if you need form validation
8
use App\Http\Traits\UsesPolicies;
9
use App\Models\Vocabulary;
10
use Backpack\CRUD\app\Http\Controllers\CrudController;
11
12
class VocabularyCrudController extends CrudController
13
{
14
    use UsesPolicies;
15
16
    public function setup()
17
    {
18
19
        /*
20
        |--------------------------------------------------------------------------
21
        | BASIC CRUD INFORMATION
22
        |--------------------------------------------------------------------------
23
        */
24
        $this->crud->setModel(Vocabulary::class);
25
        $this->crud->setRoute(config('backpack.base.route_prefix') . '/projects/' . request()->project . '/vocabularies');
26
        $this->crud->setEntityNameStrings('Vocabulary', 'Vocabularies');
27
28
        /*
29
        |--------------------------------------------------------------------------
30
        | BASIC CRUD INFORMATION
31
        |--------------------------------------------------------------------------
32
        */
33
34
        $this->crud->setFromDb();
35
36
        // ------ CRUD FIELDS
37
        // $this->crud->addField($options, 'update/create/both');
38
        // $this->crud->addFields($array_of_arrays, 'update/create/both');
39
        // $this->crud->removeField('name', 'update/create/both');
40
        // $this->crud->removeFields($array_of_names, 'update/create/both');
41
42
        // ------ CRUD COLUMNS
43
        // $this->crud->addColumn(); // add a single column, at the end of the stack
44
        // $this->crud->addColumns(); // add multiple columns, at the end of the stack
45
        // $this->crud->removeColumn('column_name'); // remove a column from the stack
46
        // $this->crud->removeColumns(['column_name_1', 'column_name_2']); // remove an array of columns from the stack
47
        // $this->crud->setColumnDetails('column_name', ['attribute' => 'value']); // adjusts the properties of the passed in column (by name)
48
        // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']);
49
50
        // ------ CRUD BUTTONS
51
        // possible positions: 'beginning' and 'end'; defaults to 'beginning' for the 'line' stack, 'end' for the others;
52
        // $this->crud->addButton($stack, $name, $type, $content, $position); // add a button; possible types are: view, model_function
53
        // $this->crud->addButtonFromModelFunction($stack, $name, $model_function_name, $position); // add a button whose HTML is returned by a method in the CRUD model
54
        // $this->crud->addButtonFromView($stack, $name, $view, $position); // add a button whose HTML is in a view placed at resources\views\vendor\backpack\crud\buttons
55
        // $this->crud->removeButton($name);
56
        // $this->crud->removeButtonFromStack($name, $stack);
57
        // $this->crud->removeAllButtons();
58
        // $this->crud->removeAllButtonsFromStack('line');
59
60
        // ------ CRUD ACCESS
61
        // $this->crud->allowAccess(['list', 'create', 'update', 'reorder', 'delete']);
62
        // $this->crud->denyAccess(['list', 'create', 'update', 'reorder', 'delete']);
63
64
        // ------ CRUD REORDER
65
        // $this->crud->enableReorder('label_name', MAX_TREE_LEVEL);
66
        // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('reorder');
67
68
        // ------ CRUD DETAILS ROW
69
        // $this->crud->enableDetailsRow();
70
        // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('details_row');
71
        // 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
72
73
        // ------ REVISIONS
74
        // You also need to use \Venturecraft\Revisionable\RevisionableTrait;
75
        // Please check out: https://laravel-backpack.readme.io/docs/crud#revisions
76
        // $this->crud->allowAccess('revisions');
77
78
        // ------ AJAX TABLE VIEW
79
        // Please note the drawbacks of this though:
80
        // - 1-n and n-n columns are not searchable
81
        // - date and datetime columns won't be sortable anymore
82
        // $this->crud->enableAjaxTable();
83
84
        // ------ DATATABLE EXPORT BUTTONS
85
        // Show export to PDF, CSV, XLS and Print buttons on the table view.
86
        // Does not work well with AJAX datatables.
87
        // $this->crud->enableExportButtons();
88
89
        // ------ ADVANCED QUERIES
90
        // $this->crud->addClause('active');
91
        // $this->crud->addClause('type', 'car');
92
        // $this->crud->addClause('where', 'name', '==', 'car');
93
        // $this->crud->addClause('whereName', 'car');
94
        // $this->crud->addClause('whereHas', 'posts', function($query) {
95
        //     $query->activePosts();
96
        // });
97
        // $this->crud->addClause('withoutGlobalScopes');
98
        // $this->crud->addClause('withoutGlobalScope', VisibleScope::class);
99
        // $this->crud->with(); // eager load relationships
100
        // $this->crud->orderBy();
101
        // $this->crud->groupBy();
102
        // $this->crud->limit();
103
    }
104
105
    public function store(StoreRequest $request)
106
    {
107
        // your additional operations before save here
108
        $redirect_location = parent::storeCrud();
109
        // your additional operations after save here
110
        // use $this->data['entry'] or $this->crud->entry
111
        return $redirect_location;
112
    }
113
114
    public function update(UpdateRequest $request)
115
    {
116
        // your additional operations before save here
117
        $redirect_location = parent::updateCrud();
118
        // your additional operations after save here
119
        // use $this->data['entry'] or $this->crud->entry
120
        return $redirect_location;
121
    }
122
}
123