Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Form often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Form, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 74 | class Form implements Renderable |
||
| 75 | { |
||
| 76 | use HasHooks; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Remove flag in `has many` form. |
||
| 80 | */ |
||
| 81 | const REMOVE_FLAG_NAME = '_remove_'; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Eloquent model of the form. |
||
| 85 | * |
||
| 86 | * @var Model |
||
| 87 | */ |
||
| 88 | protected $model; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var \Illuminate\Validation\Validator |
||
| 92 | */ |
||
| 93 | protected $validator; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var Builder |
||
| 97 | */ |
||
| 98 | protected $builder; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Data for save to current model from input. |
||
| 102 | * |
||
| 103 | * @var array |
||
| 104 | */ |
||
| 105 | protected $updates = []; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Data for save to model's relations from input. |
||
| 109 | * |
||
| 110 | * @var array |
||
| 111 | */ |
||
| 112 | protected $relations = []; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Input data. |
||
| 116 | * |
||
| 117 | * @var array |
||
| 118 | */ |
||
| 119 | protected $inputs = []; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Available fields. |
||
| 123 | * |
||
| 124 | * @var array |
||
| 125 | */ |
||
| 126 | public static $availableFields = [ |
||
| 127 | 'button' => Field\Button::class, |
||
| 128 | 'checkbox' => Field\Checkbox::class, |
||
| 129 | 'color' => Field\Color::class, |
||
| 130 | 'currency' => Field\Currency::class, |
||
| 131 | 'date' => Field\Date::class, |
||
| 132 | 'dateRange' => Field\DateRange::class, |
||
| 133 | 'datetime' => Field\Datetime::class, |
||
| 134 | 'dateTimeRange' => Field\DatetimeRange::class, |
||
| 135 | 'datetimeRange' => Field\DatetimeRange::class, |
||
| 136 | 'decimal' => Field\Decimal::class, |
||
| 137 | 'display' => Field\Display::class, |
||
| 138 | 'divider' => Field\Divider::class, |
||
| 139 | 'embeds' => Field\Embeds::class, |
||
| 140 | 'email' => Field\Email::class, |
||
| 141 | 'file' => Field\File::class, |
||
| 142 | 'hasMany' => Field\HasMany::class, |
||
| 143 | 'hidden' => Field\Hidden::class, |
||
| 144 | 'id' => Field\Id::class, |
||
| 145 | 'image' => Field\Image::class, |
||
| 146 | 'ip' => Field\Ip::class, |
||
| 147 | 'mobile' => Field\Mobile::class, |
||
| 148 | 'month' => Field\Month::class, |
||
| 149 | 'multipleSelect' => Field\MultipleSelect::class, |
||
| 150 | 'number' => Field\Number::class, |
||
| 151 | 'password' => Field\Password::class, |
||
| 152 | 'radio' => Field\Radio::class, |
||
| 153 | 'rate' => Field\Rate::class, |
||
| 154 | 'select' => Field\Select::class, |
||
| 155 | 'slider' => Field\Slider::class, |
||
| 156 | 'switch' => Field\SwitchField::class, |
||
| 157 | 'text' => Field\Text::class, |
||
| 158 | 'textarea' => Field\Textarea::class, |
||
| 159 | 'time' => Field\Time::class, |
||
| 160 | 'timeRange' => Field\TimeRange::class, |
||
| 161 | 'url' => Field\Url::class, |
||
| 162 | 'year' => Field\Year::class, |
||
| 163 | 'html' => Field\Html::class, |
||
| 164 | 'tags' => Field\Tags::class, |
||
| 165 | 'icon' => Field\Icon::class, |
||
| 166 | 'multipleFile' => Field\MultipleFile::class, |
||
| 167 | 'multipleImage' => Field\MultipleImage::class, |
||
| 168 | 'captcha' => Field\Captcha::class, |
||
| 169 | 'listbox' => Field\Listbox::class, |
||
| 170 | 'table' => Field\Table::class, |
||
| 171 | 'timezone' => Field\Timezone::class, |
||
| 172 | 'keyValue' => Field\KeyValue::class, |
||
| 173 | 'list' => Field\ListField::class, |
||
| 174 | ]; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Form field alias. |
||
| 178 | * |
||
| 179 | * @var array |
||
| 180 | */ |
||
| 181 | public static $fieldAlias = []; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Ignored saving fields. |
||
| 185 | * |
||
| 186 | * @var array |
||
| 187 | */ |
||
| 188 | protected $ignored = []; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Collected field assets. |
||
| 192 | * |
||
| 193 | * @var array |
||
| 194 | */ |
||
| 195 | protected static $collectedAssets = []; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @var Form\Tab |
||
| 199 | */ |
||
| 200 | protected $tab = null; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Field rows in form. |
||
| 204 | * |
||
| 205 | * @var array |
||
| 206 | */ |
||
| 207 | public $rows = []; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @var bool |
||
| 211 | */ |
||
| 212 | protected $isSoftDeletes = false; |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Initialization closure array. |
||
| 216 | * |
||
| 217 | * @var []Closure |
||
| 218 | */ |
||
| 219 | protected static $initCallbacks; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Create a new form instance. |
||
| 223 | * |
||
| 224 | * @param $model |
||
| 225 | * @param \Closure $callback |
||
| 226 | */ |
||
| 227 | public function __construct($model, Closure $callback = null) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Initialize with user pre-defined default disables, etc. |
||
| 244 | * |
||
| 245 | * @param Closure $callback |
||
| 246 | */ |
||
| 247 | public static function init(Closure $callback = null) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Call the initialization closure array in sequence. |
||
| 254 | */ |
||
| 255 | protected function callInitCallbacks() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @param Field $field |
||
| 268 | * |
||
| 269 | * @return $this |
||
| 270 | */ |
||
| 271 | public function pushField(Field $field) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @return Model |
||
| 282 | */ |
||
| 283 | public function model() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @return Builder |
||
| 290 | */ |
||
| 291 | public function builder() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Generate a edit form. |
||
| 298 | * |
||
| 299 | * @param $id |
||
| 300 | * |
||
| 301 | * @return $this |
||
| 302 | */ |
||
| 303 | public function edit($id) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Use tab to split form. |
||
| 315 | * |
||
| 316 | * @param string $title |
||
| 317 | * @param Closure $content |
||
| 318 | * |
||
| 319 | * @return $this |
||
| 320 | */ |
||
| 321 | public function tab($title, Closure $content, $active = false) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Get Tab instance. |
||
| 330 | * |
||
| 331 | * @return Tab |
||
| 332 | */ |
||
| 333 | public function getTab() |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Destroy data entity and remove files. |
||
| 344 | * |
||
| 345 | * @param $id |
||
| 346 | * |
||
| 347 | * @return mixed |
||
| 348 | */ |
||
| 349 | public function destroy($id) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Remove files in record. |
||
| 396 | * |
||
| 397 | * @param Model $model |
||
| 398 | * @param bool $forceDelete |
||
| 399 | */ |
||
| 400 | protected function deleteFiles(Model $model, $forceDelete = false) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Store a new record. |
||
| 420 | * |
||
| 421 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\Http\JsonResponse |
||
| 422 | */ |
||
| 423 | public function store() |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @param MessageBag $message |
||
| 461 | * |
||
| 462 | * @return $this|\Illuminate\Http\JsonResponse |
||
| 463 | */ |
||
| 464 | protected function responseValidationError(MessageBag $message) |
||
| 465 | { |
||
| 466 | if (\request()->ajax() && !\request()->pjax()) { |
||
| 467 | return response()->json([ |
||
| 468 | 'status' => false, |
||
| 469 | 'validation' => $message, |
||
| 470 | 'message' => $message->first(), |
||
| 471 | ]); |
||
| 472 | } |
||
| 473 | |||
| 474 | return back()->withInput()->withErrors($message); |
||
| 475 | } |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Get ajax response. |
||
| 479 | * |
||
| 480 | * @param string $message |
||
| 481 | * |
||
| 482 | * @return bool|\Illuminate\Http\JsonResponse |
||
| 483 | */ |
||
| 484 | protected function ajaxResponse($message) |
||
| 485 | { |
||
| 486 | $request = Request::capture(); |
||
| 487 | |||
| 488 | // ajax but not pjax |
||
| 489 | if ($request->ajax() && !$request->pjax()) { |
||
| 490 | return response()->json([ |
||
| 491 | 'status' => true, |
||
| 492 | 'message' => $message, |
||
| 493 | ]); |
||
| 494 | } |
||
| 495 | |||
| 496 | return false; |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Prepare input data for insert or update. |
||
| 501 | * |
||
| 502 | * @param array $data |
||
| 503 | * |
||
| 504 | * @return mixed |
||
| 505 | */ |
||
| 506 | protected function prepare($data = []) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Remove ignored fields from input. |
||
| 525 | * |
||
| 526 | * @param array $input |
||
| 527 | * |
||
| 528 | * @return array |
||
| 529 | */ |
||
| 530 | protected function removeIgnoredFields($input) |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Get inputs for relations. |
||
| 539 | * |
||
| 540 | * @param array $inputs |
||
| 541 | * |
||
| 542 | * @return array |
||
| 543 | */ |
||
| 544 | protected function getRelationInputs($inputs = []) |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Handle update. |
||
| 565 | * |
||
| 566 | * @param int $id |
||
| 567 | * @param null $data |
||
| 568 | * |
||
| 569 | * @return bool|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|mixed|null|Response |
||
| 570 | */ |
||
| 571 | public function update($id, $data = null) |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Get RedirectResponse after store. |
||
| 631 | * |
||
| 632 | * @return \Illuminate\Http\RedirectResponse |
||
| 633 | */ |
||
| 634 | protected function redirectAfterStore() |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Get RedirectResponse after update. |
||
| 645 | * |
||
| 646 | * @param mixed $key |
||
| 647 | * |
||
| 648 | * @return \Illuminate\Http\RedirectResponse |
||
| 649 | */ |
||
| 650 | protected function redirectAfterUpdate($key) |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Get RedirectResponse after data saving. |
||
| 659 | * |
||
| 660 | * @param string $resourcesPath |
||
| 661 | * @param string $key |
||
| 662 | * |
||
| 663 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
||
| 664 | */ |
||
| 665 | protected function redirectAfterSaving($resourcesPath, $key) |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Check if request is from editable. |
||
| 687 | * |
||
| 688 | * @param array $input |
||
| 689 | * |
||
| 690 | * @return bool |
||
| 691 | */ |
||
| 692 | protected function isEditable(array $input = []) |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Handle updates for single column. |
||
| 699 | * |
||
| 700 | * @param int $id |
||
| 701 | * @param array $data |
||
| 702 | * |
||
| 703 | * @return array|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|Response |
||
| 704 | */ |
||
| 705 | protected function handleColumnUpdates($id, $data) |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Handle editable update. |
||
| 725 | * |
||
| 726 | * @param array $input |
||
| 727 | * |
||
| 728 | * @return array |
||
| 729 | */ |
||
| 730 | protected function handleEditable(array $input = []) |
||
| 742 | |||
| 743 | /** |
||
| 744 | * @param array $input |
||
| 745 | * |
||
| 746 | * @return array |
||
| 747 | */ |
||
| 748 | protected function handleFileDelete(array $input = []) |
||
| 759 | |||
| 760 | /** |
||
| 761 | * @param array $input |
||
| 762 | * |
||
| 763 | * @return array |
||
| 764 | */ |
||
| 765 | protected function handleFileSort(array $input = []) |
||
| 785 | |||
| 786 | /** |
||
| 787 | * Handle orderable update. |
||
| 788 | * |
||
| 789 | * @param int $id |
||
| 790 | * @param array $input |
||
| 791 | * |
||
| 792 | * @return bool |
||
| 793 | */ |
||
| 794 | protected function handleOrderable($id, array $input = []) |
||
| 808 | |||
| 809 | /** |
||
| 810 | * Update relation data. |
||
| 811 | * |
||
| 812 | * @param array $relationsData |
||
| 813 | * |
||
| 814 | * @return void |
||
| 815 | */ |
||
| 816 | protected function updateRelation($relationsData) |
||
| 923 | |||
| 924 | /** |
||
| 925 | * Prepare input data for update. |
||
| 926 | * |
||
| 927 | * @param array $updates |
||
| 928 | * @param bool $oneToOneRelation If column is one-to-one relation. |
||
| 929 | * |
||
| 930 | * @return array |
||
| 931 | */ |
||
| 932 | protected function prepareUpdate(array $updates, $oneToOneRelation = false) |
||
| 964 | |||
| 965 | /** |
||
| 966 | * @param string|array $columns |
||
| 967 | * @param bool $containsDot |
||
| 968 | * |
||
| 969 | * @return bool |
||
| 970 | */ |
||
| 971 | protected function isInvalidColumn($columns, $containsDot = false) |
||
| 982 | |||
| 983 | /** |
||
| 984 | * Prepare input data for insert. |
||
| 985 | * |
||
| 986 | * @param $inserts |
||
| 987 | * |
||
| 988 | * @return array |
||
| 989 | */ |
||
| 990 | protected function prepareInsert($inserts) |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Is input data is has-one relation. |
||
| 1016 | * |
||
| 1017 | * @param array $inserts |
||
| 1018 | * |
||
| 1019 | * @return bool |
||
| 1020 | */ |
||
| 1021 | protected function isHasOneRelation($inserts) |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Ignore fields to save. |
||
| 1038 | * |
||
| 1039 | * @param string|array $fields |
||
| 1040 | * |
||
| 1041 | * @return $this |
||
| 1042 | */ |
||
| 1043 | public function ignore($fields) |
||
| 1049 | |||
| 1050 | /** |
||
| 1051 | * @param array $data |
||
| 1052 | * @param string|array $columns |
||
| 1053 | * |
||
| 1054 | * @return array|mixed |
||
| 1055 | */ |
||
| 1056 | View Code Duplication | protected function getDataByColumn($data, $columns) |
|
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Find field object by column. |
||
| 1077 | * |
||
| 1078 | * @param $column |
||
| 1079 | * |
||
| 1080 | * @return mixed |
||
| 1081 | */ |
||
| 1082 | protected function getFieldByColumn($column) |
||
| 1094 | |||
| 1095 | /** |
||
| 1096 | * Set original data for each field. |
||
| 1097 | * |
||
| 1098 | * @return void |
||
| 1099 | */ |
||
| 1100 | protected function setFieldOriginalValue() |
||
| 1110 | |||
| 1111 | /** |
||
| 1112 | * Set all fields value in form. |
||
| 1113 | * |
||
| 1114 | * @param $id |
||
| 1115 | * |
||
| 1116 | * @return void |
||
| 1117 | */ |
||
| 1118 | protected function setFieldValue($id) |
||
| 1142 | |||
| 1143 | /** |
||
| 1144 | * Add a fieldset to form. |
||
| 1145 | * |
||
| 1146 | * @param string $title |
||
| 1147 | * @param Closure $setCallback |
||
| 1148 | * |
||
| 1149 | * @return Field\Fieldset |
||
| 1150 | */ |
||
| 1151 | View Code Duplication | public function fieldset(string $title, Closure $setCallback) |
|
| 1163 | |||
| 1164 | /** |
||
| 1165 | * Don't snake case attributes. |
||
| 1166 | * |
||
| 1167 | * @param Model $model |
||
| 1168 | * |
||
| 1169 | * @return void |
||
| 1170 | */ |
||
| 1171 | protected static function doNotSnakeAttributes(Model $model) |
||
| 1177 | |||
| 1178 | /** |
||
| 1179 | * Get validation messages. |
||
| 1180 | * |
||
| 1181 | * @param array $input |
||
| 1182 | * |
||
| 1183 | * @return MessageBag|bool |
||
| 1184 | */ |
||
| 1185 | public function validationMessages($input) |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Merge validation messages from input validators. |
||
| 1207 | * |
||
| 1208 | * @param \Illuminate\Validation\Validator[] $validators |
||
| 1209 | * |
||
| 1210 | * @return MessageBag |
||
| 1211 | */ |
||
| 1212 | protected function mergeValidationMessages($validators) |
||
| 1222 | |||
| 1223 | /** |
||
| 1224 | * Get all relations of model from callable. |
||
| 1225 | * |
||
| 1226 | * @return array |
||
| 1227 | */ |
||
| 1228 | public function getRelations() |
||
| 1255 | |||
| 1256 | /** |
||
| 1257 | * Set action for form. |
||
| 1258 | * |
||
| 1259 | * @param string $action |
||
| 1260 | * |
||
| 1261 | * @return $this |
||
| 1262 | */ |
||
| 1263 | public function setAction($action) |
||
| 1269 | |||
| 1270 | /** |
||
| 1271 | * Set field and label width in current form. |
||
| 1272 | * |
||
| 1273 | * @param int $fieldWidth |
||
| 1274 | * @param int $labelWidth |
||
| 1275 | * |
||
| 1276 | * @return $this |
||
| 1277 | */ |
||
| 1278 | public function setWidth($fieldWidth = 8, $labelWidth = 2) |
||
| 1289 | |||
| 1290 | /** |
||
| 1291 | * Set view for form. |
||
| 1292 | * |
||
| 1293 | * @param string $view |
||
| 1294 | * |
||
| 1295 | * @return $this |
||
| 1296 | */ |
||
| 1297 | public function setView($view) |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Set title for form. |
||
| 1306 | * |
||
| 1307 | * @param string $title |
||
| 1308 | * |
||
| 1309 | * @return $this |
||
| 1310 | */ |
||
| 1311 | public function setTitle($title = '') |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Add a row in form. |
||
| 1320 | * |
||
| 1321 | * @param Closure $callback |
||
| 1322 | * |
||
| 1323 | * @return $this |
||
| 1324 | */ |
||
| 1325 | public function row(Closure $callback) |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Tools setting for form. |
||
| 1334 | * |
||
| 1335 | * @param Closure $callback |
||
| 1336 | */ |
||
| 1337 | public function tools(Closure $callback) |
||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * @param Closure|null $callback |
||
| 1344 | * |
||
| 1345 | * @return Form\Tools |
||
| 1346 | */ |
||
| 1347 | public function header(Closure $callback = null) |
||
| 1355 | |||
| 1356 | /** |
||
| 1357 | * Indicates if current form page is creating. |
||
| 1358 | * |
||
| 1359 | * @return bool |
||
| 1360 | */ |
||
| 1361 | public function isCreating() |
||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * Indicates if current form page is editing. |
||
| 1368 | * |
||
| 1369 | * @return bool |
||
| 1370 | */ |
||
| 1371 | public function isEditing() |
||
| 1375 | |||
| 1376 | /** |
||
| 1377 | * Disable form submit. |
||
| 1378 | * |
||
| 1379 | * @param bool $disable |
||
| 1380 | * |
||
| 1381 | * @return $this |
||
| 1382 | * |
||
| 1383 | * @deprecated |
||
| 1384 | */ |
||
| 1385 | public function disableSubmit(bool $disable = true) |
||
| 1391 | |||
| 1392 | /** |
||
| 1393 | * Disable form reset. |
||
| 1394 | * |
||
| 1395 | * @param bool $disable |
||
| 1396 | * |
||
| 1397 | * @return $this |
||
| 1398 | * |
||
| 1399 | * @deprecated |
||
| 1400 | */ |
||
| 1401 | public function disableReset(bool $disable = true) |
||
| 1407 | |||
| 1408 | /** |
||
| 1409 | * Disable View Checkbox on footer. |
||
| 1410 | * |
||
| 1411 | * @param bool $disable |
||
| 1412 | * |
||
| 1413 | * @return $this |
||
| 1414 | */ |
||
| 1415 | public function disableViewCheck(bool $disable = true) |
||
| 1421 | |||
| 1422 | /** |
||
| 1423 | * Disable Editing Checkbox on footer. |
||
| 1424 | * |
||
| 1425 | * @param bool $disable |
||
| 1426 | * |
||
| 1427 | * @return $this |
||
| 1428 | */ |
||
| 1429 | public function disableEditingCheck(bool $disable = true) |
||
| 1435 | |||
| 1436 | /** |
||
| 1437 | * Disable Creating Checkbox on footer. |
||
| 1438 | * |
||
| 1439 | * @param bool $disable |
||
| 1440 | * |
||
| 1441 | * @return $this |
||
| 1442 | */ |
||
| 1443 | public function disableCreatingCheck(bool $disable = true) |
||
| 1449 | |||
| 1450 | /** |
||
| 1451 | * Footer setting for form. |
||
| 1452 | * |
||
| 1453 | * @param Closure $callback |
||
| 1454 | */ |
||
| 1455 | public function footer(Closure $callback = null) |
||
| 1463 | |||
| 1464 | /** |
||
| 1465 | * Get current resource route url. |
||
| 1466 | * |
||
| 1467 | * @param int $slice |
||
| 1468 | * |
||
| 1469 | * @return string |
||
| 1470 | */ |
||
| 1471 | public function resource($slice = -2) |
||
| 1481 | |||
| 1482 | /** |
||
| 1483 | * Render the form contents. |
||
| 1484 | * |
||
| 1485 | * @return string |
||
| 1486 | */ |
||
| 1487 | public function render() |
||
| 1495 | |||
| 1496 | /** |
||
| 1497 | * Get or set input data. |
||
| 1498 | * |
||
| 1499 | * @param string $key |
||
| 1500 | * @param null $value |
||
| 1501 | * |
||
| 1502 | * @return array|mixed |
||
| 1503 | */ |
||
| 1504 | public function input($key, $value = null) |
||
| 1512 | |||
| 1513 | /** |
||
| 1514 | * Register custom field. |
||
| 1515 | * |
||
| 1516 | * @param string $abstract |
||
| 1517 | * @param string $class |
||
| 1518 | * |
||
| 1519 | * @return void |
||
| 1520 | */ |
||
| 1521 | public static function extend($abstract, $class) |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * Set form field alias. |
||
| 1528 | * |
||
| 1529 | * @param string $field |
||
| 1530 | * @param string $alias |
||
| 1531 | * |
||
| 1532 | * @return void |
||
| 1533 | */ |
||
| 1534 | public static function alias($field, $alias) |
||
| 1538 | |||
| 1539 | /** |
||
| 1540 | * Remove registered field. |
||
| 1541 | * |
||
| 1542 | * @param array|string $abstract |
||
| 1543 | */ |
||
| 1544 | public static function forget($abstract) |
||
| 1548 | |||
| 1549 | /** |
||
| 1550 | * Find field class. |
||
| 1551 | * |
||
| 1552 | * @param string $method |
||
| 1553 | * |
||
| 1554 | * @return bool|mixed |
||
| 1555 | */ |
||
| 1556 | public static function findFieldClass($method) |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Collect assets required by registered field. |
||
| 1574 | * |
||
| 1575 | * @return array |
||
| 1576 | */ |
||
| 1577 | public static function collectFieldAssets() |
||
| 1602 | |||
| 1603 | /** |
||
| 1604 | * Getter. |
||
| 1605 | * |
||
| 1606 | * @param string $name |
||
| 1607 | * |
||
| 1608 | * @return array|mixed |
||
| 1609 | */ |
||
| 1610 | public function __get($name) |
||
| 1614 | |||
| 1615 | /** |
||
| 1616 | * Setter. |
||
| 1617 | * |
||
| 1618 | * @param string $name |
||
| 1619 | * @param mixed $value |
||
| 1620 | * |
||
| 1621 | * @return array |
||
| 1622 | */ |
||
| 1623 | public function __set($name, $value) |
||
| 1627 | |||
| 1628 | /** |
||
| 1629 | * Generate a Field object and add to form builder if Field exists. |
||
| 1630 | * |
||
| 1631 | * @param string $method |
||
| 1632 | * @param array $arguments |
||
| 1633 | * |
||
| 1634 | * @return Field |
||
| 1635 | */ |
||
| 1636 | public function __call($method, $arguments) |
||
| 1652 | } |
||
| 1653 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: