ProjectPrefixCrudController::store()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Frontend\Project;
4
5
use App\Http\Requests\Frontend\Project\ProjectPrefixRequest as StoreRequest;
6
// VALIDATION: change the requests to match your own file names if you need form validation
7
use App\Http\Requests\Frontend\Project\ProjectPrefixRequest as UpdateRequest;
8
use App\Models\Project;
9
use Backpack\CRUD\app\Http\Controllers\CrudController;
10
use Illuminate\Support\Facades\Route;
11
12
class ProjectPrefixCrudController extends CrudController
13
{
14
    /**
15
     * @throws \Exception
16
     */
17
    public function setup()
18
    {
19
20
        /*
21
        |--------------------------------------------------------------------------
22
        | BASIC CRUD INFORMATION
23
        |--------------------------------------------------------------------------
24
        */
25
        $project_id = Route::current()->parameter('project_id') ?? Route::current()->parameter('project');
26
27
        $this->crud->setModel(Project::class);
28
        $this->crud->setRoute(config('backpack.base.route_prefix') . '/projects/' . $project_id . '/prefixes');
0 ignored issues
show
Bug introduced by
Are you sure $project_id of type object|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        $this->crud->setRoute(config('backpack.base.route_prefix') . '/projects/' . /** @scrutinizer ignore-type */ $project_id . '/prefixes');
Loading history...
29
        $this->crud->setEntityNameStrings('Prefix', 'Prefixes');
30
31
        /** @var Project $project */
32
        $project  = $this->crud->getModel();
33
        $prefixes = $project->prefixes;
0 ignored issues
show
Unused Code introduced by
The assignment to $prefixes is dead and can be removed.
Loading history...
34
35
        /*
36
        |--------------------------------------------------------------------------
37
        | BASIC CRUD INFORMATION
38
        |--------------------------------------------------------------------------
39
        */
40
41
        // ------ CRUD FIELDS
42
        // $this->crud->addField([
43
        //
44
        // ]);
45
        // $this->crud->addFields($array_of_arrays, 'update/create/both');
46
        // $this->crud->removeField('name', 'update/create/both');
47
        // $this->crud->removeFields($array_of_names, 'update/create/both');
48
49
        // ------ CRUD COLUMNS
50
        // $this->crud->addColumn(); // add a single column, at the end of the stack
51
        // $this->crud->addColumns(); // add multiple columns, at the end of the stack
52
        // $this->crud->removeColumn('column_name'); // remove a column from the stack
53
        // $this->crud->removeColumns(['column_name_1', 'column_name_2']); // remove an array of columns from the stack
54
        // $this->crud->setColumnDetails('column_name', ['attribute' => 'value']); // adjusts the properties of the passed in column (by name)
55
        // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']);
56
57
        // ------ CRUD BUTTONS
58
        // possible positions: 'beginning' and 'end'; defaults to 'beginning' for the 'line' stack, 'end' for the others;
59
        // $this->crud->addButton($stack, $name, $type, $content, $position); // add a button; possible types are: view, model_function
60
        // $this->crud->addButtonFromModelFunction($stack, $name, $model_function_name, $position); // add a button whose HTML is returned by a method in the CRUD model
61
        // $this->crud->addButtonFromView($stack, $name, $view, $position); // add a button whose HTML is in a view placed at resources\views\vendor\backpack\crud\buttons
62
        // $this->crud->removeButton($name);
63
        // $this->crud->removeButtonFromStack($name, $stack);
64
        // $this->crud->removeAllButtons();
65
        // $this->crud->removeAllButtonsFromStack('line');
66
67
        // ------ CRUD ACCESS
68
        // $this->crud->allowAccess(['list', 'create', 'update', 'reorder', 'delete']);
69
        // $this->crud->denyAccess(['list', 'create', 'update', 'reorder', 'delete']);
70
71
        // ------ CRUD REORDER
72
        // $this->crud->enableReorder('label_name', MAX_TREE_LEVEL);
73
        // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('reorder');
74
75
        // ------ CRUD DETAILS ROW
76
        // $this->crud->enableDetailsRow();
77
        // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('details_row');
78
        // 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
79
80
        // ------ REVISIONS
81
        // You also need to use \Venturecraft\Revisionable\RevisionableTrait;
82
        // Please check out: https://laravel-backpack.readme.io/docs/crud#revisions
83
        // $this->crud->allowAccess('revisions');
84
85
        // ------ AJAX TABLE VIEW
86
        // Please note the drawbacks of this though:
87
        // - 1-n and n-n columns are not searchable
88
        // - date and datetime columns won't be sortable anymore
89
        // $this->crud->enableAjaxTable();
90
91
        // ------ DATATABLE EXPORT BUTTONS
92
        // Show export to PDF, CSV, XLS and Print buttons on the table view.
93
        // Does not work well with AJAX datatables.
94
        // $this->crud->enableExportButtons();
95
96
        // ------ ADVANCED QUERIES
97
        // $this->crud->addClause('active');
98
        // $this->crud->addClause('type', 'car');
99
        // $this->crud->addClause('where', 'name', '==', 'car');
100
        // $this->crud->addClause('whereName', 'car');
101
        // $this->crud->addClause('whereHas', 'posts', function($query) {
102
        //     $query->activePosts();
103
        // });
104
        // $this->crud->addClause('withoutGlobalScopes');
105
        // $this->crud->addClause('withoutGlobalScope', VisibleScope::class);
106
        // $this->crud->with(); // eager load relationships
107
        // $this->crud->orderBy();
108
        // $this->crud->groupBy();
109
        // $this->crud->limit();
110
    }
111
112
    /**
113
     * @param UpdateRequest $request
114
     *
115
     * @return \Illuminate\Http\RedirectResponse
116
     */
117
    public function store(StoreRequest $request)
118
    {
119
        // your additional operations before save here
120
        $redirect_location = parent::storeCrud($request);
0 ignored issues
show
Bug introduced by
$request of type App\Http\Requests\Fronte...ct\ProjectPrefixRequest is incompatible with the type null|Backpack\CRUD\app\Http\Requests\CrudRequest expected by parameter $request of Backpack\CRUD\app\Http\C...Controller::storeCrud(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

120
        $redirect_location = parent::storeCrud(/** @scrutinizer ignore-type */ $request);
Loading history...
121
        // your additional operations after save here
122
        // use $this->data['entry'] or $this->crud->entry
123
        return $redirect_location;
124
    }
125
126
    /**
127
     * @param UpdateRequest $request
128
     *
129
     * @return \Illuminate\Http\RedirectResponse
130
     */
131
    public function update(UpdateRequest $request)
132
    {
133
        // your additional operations before save here
134
        $redirect_location = parent::updateCrud($request);
0 ignored issues
show
Bug introduced by
$request of type App\Http\Requests\Fronte...ct\ProjectPrefixRequest is incompatible with the type null|Backpack\CRUD\app\Http\Requests\CrudRequest expected by parameter $request of Backpack\CRUD\app\Http\C...ontroller::updateCrud(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

134
        $redirect_location = parent::updateCrud(/** @scrutinizer ignore-type */ $request);
Loading history...
135
        // your additional operations after save here
136
        // use $this->data['entry'] or $this->crud->entry
137
        return $redirect_location;
138
    }
139
}
140