| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Http\Controllers\Admin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Backpack\CRUD\app\Http\Controllers\CrudController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Facades\App; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use App\Models\Lookup\SkillType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | // Validation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use App\Http\Requests\SkillCrudRequest as StoreRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use App\Http\Requests\SkillCrudRequest as UpdateRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class SkillCrudController extends CrudController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * Prepare the admin interface by setting the associated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * model, setting the route, and adding custom columns/fields. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 1 |  |     public function setup() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         // Workaround for how the unique_translation validation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         // works in App\Http\Requests\SkillCrudRequest. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 1 |  |         $locale = 'en'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 1 |  |         if (null !== $this->request->input('locale')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             $locale = $this->request->input('locale'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 1 |  |         App::setLocale($locale); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         // Eloquent model to associate with this collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         // of views and controller actions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 1 |  |         $this->crud->setModel('App\Models\Skill'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         // Custom backpack route. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 1 |  |         $this->crud->setRoute('admin/skill'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         // Custom strings to display within the backpack UI, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         // things like Create Skill, Delete Skills, etc. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 1 |  |         $this->crud->setEntityNameStrings('skill', 'skills'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         // Add custom columns to the Skill index view. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 1 |  |         $this->crud->addColumn([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 1 |  |             'name' => 'name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 1 |  |             'type' => 'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |             'label' => 'Name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 $query->orWhere('name->' . $locale, 'like', "%$searchTerm%"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 1 |  |             }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 return $query->orderBy('name->' . $locale, $columnDirection)->select('*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |         $this->crud->addColumn([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |             'name' => 'description', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 1 |  |             'type' => 'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |             'label' => 'Description', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 $query->orWhere('description->' . $locale, 'like', "%$searchTerm%"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  |             }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             'orderable' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |         $this->crud->addColumn([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 1 |  |             'name' => 'skill_type.name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 1 |  |             'type' => 'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 1 |  |             'label' => 'Type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             'orderable' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 return $query->orderBy('skill_type_id', $columnDirection)->select('*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 1 |  |         $this->crud->addColumn([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  |             'label' => 'Classifications', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             'type' => 'select_multiple', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             'name' => 'classifications', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             'entity' => 'classifications', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             'attribute' => 'key', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'model' => 'App\Models\Skill', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  |         $this->crud->addColumn([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 1 |  |             'name' => 'is_culture_skill', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             'label' => 'Culture', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             'type' => 'boolean', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             'orderable' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 1 |  |         $this->crud->addColumn([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 1 |  |             'name' => 'is_future_skill', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             'label' => 'Future', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             'type' => 'boolean', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             'orderable' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         // Add custom fields to the create/update views. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 1 |  |         $this->crud->addField([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 1 |  |             'name' => 'name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             'type' => 'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             'label' => 'Name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 1 |  |         $this->crud->addField([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 1 |  |             'name' => 'description', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             'type' => 'textarea', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             'label' => 'Description' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 1 |  |         $this->crud->addField([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 1 |  |             'name' => 'skill_type_id', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 1 |  |             'label' => 'Type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 1 |  |             'type' => 'select_from_array', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 1 |  |             'options' => SkillType::all()->pluck('name', 'id')->toArray(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             'allow_null' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 1 |  |         $this->crud->addField([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 1 |  |             'name' => 'classifications', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             'type' => 'select2_multiple', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             'label' => 'Classifications (select all that apply)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             'entity' => 'skills', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             'attribute' => 'key', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             'model' => 'App\Models\Classification', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             'pivot' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 1 |  |         $this->crud->addField([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 1 |  |             'name' => 'is_culture_skill', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             'label' => 'This is a culture skill', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             'type' => 'checkbox' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 1 |  |         $this->crud->addField([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 1 |  |             'name' => 'is_future_skill', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             'label' => 'This is a future skill', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             'type' => 'checkbox' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     * Action for creating a new Skill in the database. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     * @param  \App\Http\Requests\SkillCrudRequest $request Incoming form request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 144 |  |  |     */ | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |     public function store(StoreRequest $request) // phpcs:ignore | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |         return parent::storeCrud(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     * Action for creating a new Skill in the database. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     * @param  \App\Http\Requests\SkillCrudRequest $request Incoming form request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     public function update(UpdateRequest $request) // phpcs:ignore | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         return parent::updateCrud(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 160 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 161 |  |  |  | 
            
                        
This check looks for imports that have been defined, but are not used in the scope.