Conditions | 1 |
Paths | 1 |
Total Lines | 50 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
10 | public function setup() |
||
11 | { |
||
12 | $this->crud->setModel("App\Models\User"); |
||
13 | $this->crud->setRoute("admin/user"); |
||
14 | $this->crud->setEntityNameStrings('user', 'users'); |
||
15 | |||
16 | $this->crud->denyAccess('create'); |
||
17 | $this->crud->denyAccess('delete'); |
||
18 | |||
19 | $this->crud->addColumn([ |
||
20 | 'name' => 'name', |
||
21 | 'type' => 'text', |
||
22 | 'label' => 'Name' |
||
23 | ]); |
||
24 | $this->crud->addColumn([ |
||
25 | 'name' => 'email', |
||
26 | 'type' => 'text', |
||
27 | 'label' => 'Email' |
||
28 | ]); |
||
29 | $this->crud->addColumn([ |
||
30 | 'name' => 'user_role.name', |
||
31 | 'type' => 'text', |
||
32 | 'label' => 'Role' |
||
33 | ]); |
||
34 | |||
35 | $this->crud->addFilter([ |
||
36 | 'name' => 'user_role', |
||
37 | 'type' => 'select2', |
||
38 | 'label' => 'Role' |
||
39 | ], function () { |
||
40 | return UserRole::all()->keyBy('id')->pluck('name', 'id')->toArray(); |
||
41 | }, function ($value) { |
||
42 | $this->crud->addClause('where', 'user_role_id', $value); |
||
43 | }); |
||
44 | |||
45 | $this->crud->addField([ |
||
46 | 'name' => 'name', |
||
47 | 'label' => "Name", |
||
48 | 'type' => 'text', |
||
49 | 'attributes' => [ |
||
50 | 'readonly'=>'readonly' |
||
51 | ] |
||
52 | ]); |
||
53 | $this->crud->addField([ |
||
54 | 'label' => "Role", |
||
55 | 'type' => 'select', |
||
56 | 'name' => 'user_role_id', // the db column for the foreign key |
||
57 | 'entity' => 'user_role', // the method that defines the relationship in your Model |
||
58 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
59 | 'model' => "App\Models\UserRole" // foreign key model |
||
60 | ]); |
||
69 |