Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
21 | public function setup(): void |
||
22 | { |
||
23 | // Eloquent model to associate with this collection of views and controller actions. |
||
24 | $this->crud->setModel('App\Models\Lookup\JobPosterStatusTransition'); |
||
25 | // Custom backpack route. |
||
26 | $this->crud->setRoute('admin/job-poster-status-transition'); |
||
27 | // Custom strings to display within the backpack UI. |
||
28 | $this->crud->setEntityNameStrings('job status transition', 'job status transitions'); |
||
29 | |||
30 | $this->crud->operation(['create', 'update'], function () { |
||
31 | $this->crud->addField([ |
||
32 | 'name' => 'key', |
||
33 | 'type' => 'text', |
||
34 | 'label' => 'Key', |
||
35 | ]); |
||
36 | |||
37 | $this->crud->addField([ |
||
38 | 'name' => 'name', |
||
39 | 'type' => 'text', |
||
40 | 'label' => 'Name', |
||
41 | 'limit' => 120, |
||
42 | ]); |
||
43 | |||
44 | $this->crud->addField([ // Select |
||
45 | 'label' => 'Owner User Role', |
||
46 | 'type' => 'select', |
||
47 | 'name' => 'owner_user_role_id', // the db column for the foreign key |
||
48 | 'entity' => 'owner_user_role', // the method that defines the relationship in your Model |
||
49 | 'attribute' => 'key', // foreign key attribute that is shown to user |
||
50 | 'model' => \App\Models\UserRole::class, // foreign key model |
||
51 | ]); |
||
52 | |||
53 | $this->crud->addField([ // Select |
||
54 | 'label' => 'From Status', |
||
55 | 'type' => 'select', |
||
56 | 'name' => 'from_job_poster_status_id', // the db column for the foreign key |
||
57 | 'entity' => 'from', // the method that defines the relationship in your Model |
||
58 | 'attribute' => 'key', // foreign key attribute that is shown to user |
||
59 | 'model' => \App\Models\Lookup\JobPosterStatus::class, // foreign key model |
||
60 | ]); |
||
61 | |||
62 | $this->crud->addField([ // Select |
||
63 | 'label' => 'To Status', |
||
64 | 'type' => 'select', |
||
65 | 'name' => 'to_job_poster_status_id', // the db column for the foreign key |
||
66 | 'entity' => 'to', // the method that defines the relationship in your Model |
||
67 | 'attribute' => 'key', // foreign key attribute that is shown to user |
||
68 | 'model' => \App\Models\Lookup\JobPosterStatus::class, // foreign key model |
||
69 | ]); |
||
70 | |||
71 | $this->crud->addField([ |
||
72 | 'name' => 'button_style', |
||
73 | 'label' => 'Button Style', |
||
74 | 'type' => 'select_from_array', |
||
75 | 'options' => ['default' => 'default', 'stop' => 'stop', 'go' => 'go'], |
||
76 | 'allows_null' => false, |
||
77 | 'default' => 'default', |
||
78 | 'fake' => true, // show the field, but don’t store it in the database column above |
||
79 | 'store_in' => 'metadata' // [optional] the database column name where you want the fake fields to ACTUALLY be stored as a JSON array |
||
80 | ]); |
||
134 |