| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Encore\Admin\Form\Field; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Encore\Admin\Admin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Encore\Admin\Form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Encore\Admin\Form\Field; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Encore\Admin\Form\NestedForm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Database\Eloquent\Relations\HasMany as Relation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Illuminate\Database\Eloquent\Relations\MorphMany; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Illuminate\Support\Facades\Validator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Illuminate\Support\Str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Class HasMany. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class HasMany extends Field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * Relation name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     protected $relationName = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * Form builder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var \Closure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     protected $builder = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * Form data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     protected $value = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * View Mode. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * Supports `default` and `tab` currently. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     protected $viewMode = 'default'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * Available views for HasMany field. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     protected $views = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         'default' => 'admin::form.hasmany', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         'tab' => 'admin::form.hasmanytab', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * Options for template. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     protected $options = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         'allowCreate' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         'allowDelete' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * Create a new HasMany field instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @param $relationName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param array $arguments | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 75 |  | View Code Duplication |     public function __construct($relationName, $arguments = []) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->relationName = $relationName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $this->column = $relationName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         if (count($arguments) == 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             $this->label = $this->formatLabel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $this->builder = $arguments[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         if (count($arguments) == 2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             list($this->label, $this->builder) = $arguments; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * Get validator for this field. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param array $input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @return bool|Validator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     public function getValidator(array $input) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         if (!array_key_exists($this->column, $input)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 104 |  | View Code Duplication |         $array_key_attach_str = function (array $a, string $b, string $c = ".") { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             return call_user_func_array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                 'array_merge', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 array_map(function ($u, $v) use ($b, $c) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                     return ["{$b}{$c}{$u}" => $v]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 }, array_keys($a), array_values($a)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 113 |  | View Code Duplication |         $array_key_clean = function (array $a) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             $a = count($a) ? call_user_func_array('array_merge', array_map(function ($k, $v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 return [str_replace(':', '', $k) => $v]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             }, array_keys($a), array_values($a))) : $a; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             return $a; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 121 |  | View Code Duplication |         $array_key_clean_undot = function (array $a) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             if (count($a)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                 foreach ($a as $key => $val) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                     array_set($a, str_replace(':', '', $key), $val); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                     if (preg_match('/[\.\:]/', $key)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                         unset($a[$key]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             return $a; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         $input = array_only($input, $this->column); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $form = $this->buildNestedForm($this->column, $this->builder); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $rel = $this->relationName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $rules = $attributes = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $messages = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         // remove all inputs & keys marked as removed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $availInput = array_filter(array_map(function ($v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             return $v[NestedForm::REMOVE_FLAG_NAME] ? null : $v; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         }, $input[$rel])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         $keys = array_keys($availInput); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         /* @var Field $field */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         foreach ($form->fields() as $field) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             if (!$fieldRules = $field->getRules()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |             $column = $field->column(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |             $columns = is_array($column) ? $column : [$column]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             if ($field instanceof Field\MultipleSelect) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                 foreach ($keys as $key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |                     $availInput[$key][$column] = array_filter($availInput[$key][$column], 'strlen'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |                     $availInput[$key][$column] = $availInput[$key][$column] ? : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             // if($field instanceof Field\File) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             //     dd(request()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             $newColumn = call_user_func_array('array_merge', array_map(function ($u) use ($columns, $rel) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |                 return array_map(function ($k, $v) use ($u, $rel) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                             //Fix ResetInput Function! A Headache Implementation! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |                     return !$k ? "{$rel}.{$u}.{$v}" : "{$rel}.{$u}.{$v}:{$k}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |                 }, array_keys($columns), array_values($columns)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             }, $keys)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             $fieldRules = is_array($fieldRules) ? implode('|', $fieldRules) : $fieldRules; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |             $rules = array_merge($rules, call_user_func_array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |                 'array_merge', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |                 array_map(function ($v) use ($fieldRules) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |                     return [$v => $fieldRules]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |                 }, $newColumn) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             $attributes = array_merge($attributes, call_user_func_array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |                 'array_merge', | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 177 |  | View Code Duplication |                 array_map(function ($v) use ($field) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |                     //Fix ResetInput Function! A Headache Implementation! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |                     $u = $field->label(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |                     $u .= is_array($field->column()) ? '[' . explode(':', explode('.', $v)[1])[0] . ']' : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |                     return [$v => "{$u}"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |                 }, $newColumn) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             )); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 185 |  | View Code Duplication |             if ($field->validationMessages) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |                 $newMessages = array_map(function ($v) use ($field, $availInput, $array_key_attach_str) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |                     list($r, $k, $c) = explode('.', $v); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |                     //Fix ResetInput Function! A Headache Implementation! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |                     $col1 = explode(':', $c)[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |                     if (!array_key_exists($col1, $availInput[$k])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |                         return [null => null]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |                     $rows = $availInput[$k][$col1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |                     if (!is_array($rows)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |                         return $array_key_attach_str($field->validationMessages, $v); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |                     $r = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |                     foreach (array_keys($rows) as $k) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |                         $k = "{$v}{$k}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |                         $r = array_merge($r, $array_key_attach_str($field->validationMessages, $k)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |                     return $r; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |                 }, $newColumn); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |                 $newMessages = call_user_func_array('array_merge', $newMessages); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                 $messages = array_merge($messages, $newMessages); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         if (empty($rules)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         $newInput = call_user_func_array('array_merge', array_map(function ($u) use ($availInput) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |             list($rel, $key, $col) = explode('.', $u); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             $idx = "{$rel}.{$key}.{$col}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |             //Fix ResetInput Function! A Headache Implementation! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |             $col1 = explode(':', $col)[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |             if (!array_key_exists($col1, $availInput[$key])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |                 return [null => null]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |             if (is_array($availInput[$key][$col1])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |                 return call_user_func_array('array_merge', array_map(function ($x, $y) use ($idx) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |                     return ["{$idx}{$x}" => $y]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |                 }, array_keys($availInput[$key][$col1]), $availInput[$key][$col1])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |             return ["{$idx}" => $availInput[$key][$col1]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         }, array_keys($rules))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |         $newInput = $array_key_clean_undot($newInput); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         $newRules = array_map(function ($u) use ($availInput, $rules) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |             list($rel, $key, $col) = explode('.', $u); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |             $idx = "{$rel}.{$key}.{$col}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |             //Fix ResetInput Function! A Headache Implementation! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |             $col1 = explode(':', $col)[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |             if (!array_key_exists($col1, $availInput[$key])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |                 return [null => null]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |             if (is_array($availInput[$key][$col1])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |                 return call_user_func_array('array_merge', array_map(function ($x) use ($idx, $rules) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                     return ["{$idx}{$x}" => $rules[$idx]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |                 }, array_keys($availInput[$key][$col1]))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |             return ["{$idx}" => $rules[$idx]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         }, array_keys($rules)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         $newRules = array_filter(call_user_func_array('array_merge', $newRules), 'strlen', ARRAY_FILTER_USE_KEY); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         $newRules = $array_key_clean($newRules);; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $newAttributes = array_map(function ($u) use ($availInput, $attributes) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |             list($rel, $key, $col) = explode('.', $u); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |             $idx = "{$rel}.{$key}.{$col}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |             //Fix ResetInput Function! A Headache Implementation! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |             $col1 = explode(':', $col)[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |             if (!array_key_exists($col1, $availInput[$key])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |                 return [null => null]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |             } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 259 |  | View Code Duplication |             if (is_array($availInput[$key][$col1])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |                 if (array_keys($availInput[$key][$col1])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |                     return call_user_func_array('array_merge', array_map(function ($x) use ($idx, $attributes) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |                     return ["{$idx}.{$x}" => $attributes[$idx]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |                 }, array_keys($availInput[$key][$col1]))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |                 return [null => null]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |             return ["{$idx}" => $attributes[$idx]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         }, array_keys($attributes)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         $newAttributes = array_filter(call_user_func_array('array_merge', $newAttributes), 'strlen'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         $newAttributes = $array_key_clean($newAttributes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         $messages = $array_key_clean($messages); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |         if (empty($newInput)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |             $newInput = [$rel => $availInput]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         return Validator::make($newInput, $newRules, $messages, $newAttributes); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |      * Format validation attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |      * @param array  $input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |      * @param string $label | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |      * @param string $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 290 |  | View Code Duplication |     protected function formatValidationAttribute($input, $label, $column) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         $new = $attributes = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |         if (is_array($column)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |             foreach ($column as $index => $col) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |                 $new[$col . $index] = $col; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |         foreach (array_keys(array_dot($input)) as $key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |             if (is_string($column)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |                 if (Str::endsWith($key, ".$column")) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |                     $attributes[$key] = $label; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |                 foreach ($new as $k => $val) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |                     if (Str::endsWith($key, ".$k")) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |                         $attributes[$key] = $label . "[$val]"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |         return $attributes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |      * Reset input key for validation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |      * @param array $input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |      * @param array $column $column is the column name array set | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |      * @return void. | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |     protected function resetInputKey(array &$input, array $column) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |          * flip the column name array set. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |          * for example, for the DateRange, the column like as below | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |          * ["start" => "created_at", "end" => "updated_at"] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |          * to: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |          * [ "created_at" => "start", "updated_at" => "end" ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |         $column = array_flip($column); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |          * $this->column is the inputs array's node name, default is the relation name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |          * So... $input[$this->column] is the data of this column's inputs data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |          * in the HasMany relation, has many data/field set, $set is field set in the below | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |         foreach ($input[$this->column] as $index => $set) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |             /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |              * foreach the field set to find the corresponding $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |              */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 352 |  | View Code Duplication |             foreach ($set as $name => $value) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |                 /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |                  * if doesn't have column name, continue to the next loop | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |                  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |                 if (!array_key_exists($name, $column)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |                     continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |                 /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |                  * example:  $newKey = created_atstart. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |                  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |                  * Σ( ° △ °|||)︴ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |                  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |                  * I don't know why a form need range input? Only can imagine is for range search.... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |                  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |                 $newKey = $name . $column[$name]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |                 /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |                  * set new key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |                  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |                 array_set($input, "{$this->column}.$index.$newKey", $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |                 /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |                  * forget the old key and value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |                  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |                 array_forget($input, "{$this->column}.$index.$name"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |      * Prepare input data for insert or update. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |      * @param array $input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 387 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 388 |  |  |     public function prepare($input) | 
            
                                                                        
                            
            
                                    
            
            
                | 389 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 390 |  |  |         $form = $this->buildNestedForm($this->column, $this->builder); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 391 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 392 |  |  |         return $form->setOriginal($this->original, $this->getKeyName())->prepare($input); | 
            
                                                                        
                            
            
                                    
            
            
                | 393 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |      * Build a Nested form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |      * @param string   $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |      * @param \Closure $builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |      * @param null     $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |      * @return NestedForm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |     protected function buildNestedForm($column, \Closure $builder, $key = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |         $form = new Form\NestedForm($column, $key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |         $form->setForm($this->form); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |         call_user_func($builder, $form); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |         $form->hidden($this->getKeyName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |         $form->hidden(NestedForm::REMOVE_FLAG_NAME)->default(0)->addElementClass(NestedForm::REMOVE_FLAG_CLASS); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |         return $form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |      * Get the HasMany relation key name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |     protected function getKeyName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |         if (is_null($this->form)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |         return $this->form->model()->{$this->relationName}()->getRelated()->getKeyName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |      * Set view mode. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |      * @param string $mode currently support `tab` mode. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |      * @author Edwin Hui | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |     public function mode($mode) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |         $this->viewMode = $mode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |      * Use tab mode to showing hasmany field. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |      * @return HasMany | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  |     public function useTab() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |         return $this->mode('tab'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |      * Build Nested form for related data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |      * @throws \Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |     protected function buildRelatedForms() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |         if (is_null($this->form)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |             return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |         $model = $this->form->model(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |         $relation = call_user_func([$model, $this->relationName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |         if (!$relation instanceof Relation && !$relation instanceof MorphMany) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |             throw new \Exception('hasMany field must be a HasMany or MorphMany relation.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |         $forms = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |          * If redirect from `exception` or `validation error` page. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  |          * Then get form data from session flash. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |          * Else get data from database. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |         if ($values = old($this->column)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |             foreach ($values as $key => $data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |                 if ($data[NestedForm::REMOVE_FLAG_NAME] == 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |                     continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |                 $forms[$key] = $this->buildNestedForm($this->column, $this->builder, $key) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |                     ->fill($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |             foreach ($this->value as $data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |                 $key = array_get($data, $relation->getRelated()->getKeyName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |                 $forms[$key] = $this->buildNestedForm($this->column, $this->builder, $key) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |                     ->fill($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |         return $forms; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |      * Setup script for this field in different view mode. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |      * @param string $script | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |     protected function setupScript($script) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |         $method = 'setupScriptFor' . ucfirst($this->viewMode) . 'View'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |         call_user_func([$this, $method], $script); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |      * Setup default template script. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |      * @param string $templateScript | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 531 |  | View Code Duplication |     protected function setupScriptForDefaultView($templateScript) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |         $removeClass = NestedForm::REMOVE_FLAG_CLASS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |         $defaultKey = NestedForm::DEFAULT_KEY_NAME; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |          * When add a new sub form, replace all element key in new sub form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |          * @example comments[new___key__][title]  => comments[new_{index}][title] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |          * {count} is increment number of current sub form count. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |         $script = <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  | var index = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  | $('#has-many-{$this->column}').on('click', '.add', function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |     var tpl = $('template.{$this->column}-tpl'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |     index++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |     var template = tpl.html().replace(/{$defaultKey}/g, index); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |     $('.has-many-{$this->column}-forms').append(template); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |     {$templateScript} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  | $('#has-many-{$this->column}').on('click', '.remove', function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  |     $(this).closest('.has-many-{$this->column}-form').hide(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  |     $(this).closest('.has-many-{$this->column}-form').find('.$removeClass').val(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |         Admin::script($script); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |      * Setup tab template script. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  |      * @param string $templateScript | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 573 |  | View Code Duplication |     protected function setupScriptForTabView($templateScript) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 574 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 575 |  |  |         $removeClass = NestedForm::REMOVE_FLAG_CLASS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 576 |  |  |         $defaultKey = NestedForm::DEFAULT_KEY_NAME; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 577 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 578 |  |  |         $script = <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 579 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 580 |  |  | $('#has-many-{$this->column} > .nav').off('click', 'i.close-tab').on('click', 'i.close-tab', function(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 581 |  |  |     var \$navTab = $(this).siblings('a'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 582 |  |  |     var \$pane = $(\$navTab.attr('href')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 583 |  |  |     if( \$pane.hasClass('new') ){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 584 |  |  |         \$pane.remove(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 585 |  |  |     }else{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 586 |  |  |         \$pane.removeClass('active').find('.$removeClass').val(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 587 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 588 |  |  |     if(\$navTab.closest('li').hasClass('active')){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 589 |  |  |         \$navTab.closest('li').remove(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 590 |  |  |         $('#has-many-{$this->column} > .nav > li:nth-child(1) > a').tab('show'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 591 |  |  |     }else{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 592 |  |  |         \$navTab.closest('li').remove(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 593 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 594 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 595 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 596 |  |  | var index = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  | $('#has-many-{$this->column} > .header').off('click', '.add').on('click', '.add', function(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 |  |  |     index++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  |     var navTabHtml = $('#has-many-{$this->column} > template.nav-tab-tpl').html().replace(/{$defaultKey}/g, index); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 |  |  |     var paneHtml = $('#has-many-{$this->column} > template.pane-tpl').html().replace(/{$defaultKey}/g, index); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 |  |  |     $('#has-many-{$this->column} > .nav').append(navTabHtml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  |     $('#has-many-{$this->column} > .tab-content').append(paneHtml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  |     $('#has-many-{$this->column} > .nav > li:last-child a').tab('show'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  |     {$templateScript} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 606 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 607 |  |  | if ($('.has-error').length) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 608 |  |  |     $('.has-error').parent('.tab-pane').each(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 609 |  |  |         var tabId = '#'+$(this).attr('id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 610 |  |  |         $('li a[href="'+tabId+'"] i').removeClass('hide'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 611 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 612 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 613 |  |  |     var first = $('.has-error:first').parent().attr('id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 614 |  |  |     $('li a[href="#'+first+'"]').tab('show'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 615 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 616 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 617 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 618 |  |  |         Admin::script($script); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 619 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 620 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 621 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 622 |  |  |      * Disable create button. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 623 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 624 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 625 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 626 |  |  |     public function disableCreate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 627 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 628 |  |  |         $this->options['allowCreate'] = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 629 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 630 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 631 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 632 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 633 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 634 |  |  |      * Disable delete button. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 635 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 636 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 637 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 638 |  |  |     public function disableDelete() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 639 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 640 |  |  |         $this->options['allowDelete'] = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 641 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 642 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 643 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 644 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 645 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 646 |  |  |      * Render the `HasMany` field. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 647 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 648 |  |  |      * @throws \Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 649 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 650 |  |  |      * @return \Illuminate\View\View | 
            
                                                                                                            
                            
            
                                    
            
            
                | 651 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 652 |  |  |     public function render() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 653 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 654 |  |  |         // specify a view to render. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 655 |  |  |         $this->view = $this->views[$this->viewMode]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 656 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 657 |  |  |         list($template, $script) = $this->buildNestedForm($this->column, $this->builder) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 658 |  |  |             ->getTemplateHtmlAndScript(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 659 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 660 |  |  |         $this->setupScript($script); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 661 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 662 |  |  |         return parent::render()->with([ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 663 |  |  |             'forms' => $this->buildRelatedForms(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 664 |  |  |             'template' => $template, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 665 |  |  |             'relationName' => $this->relationName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 666 |  |  |             'options' => $this->options, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 667 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 668 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 669 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 670 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.