function buildForm() { $form = new LaraForm($this->relation); $form->putTbHidden('relation')->setValue($this->relation); $options = []; $model = $this->traitEntityBelongsToMany_getBelongsModel(); if ($model) { $options = $model::orderBy($this->orderByModel())->listsExt(); if (!is_array($options)) { $options = []; } } $form->putTbGroupCheckbox('belongs_to_many', $options, false); $ids = $this->ids(); $form->initValues(['belongs_to_many' => array_combine($ids, $ids)]); if ($form->validate()) { $many = $form->getFieldValue('belongs_to_many'); $filtered = array_filter($many, function ($value) { return $value; }); $ids = array_keys($filtered); $this->model->{$this->relation}()->sync($ids); } $this->traitEntityBelongsToMany_form = $form; }
function getForm() { $form = new LaraForm($this->relation); $form->putTbHidden('relation')->setValue($this->relation); $options = $this->getOptions(); if (!is_array($options)) { $options = []; } $form->putTbGroupCheckbox('has_many', $options, false); $ids = $this->ids(); $form->initValues(['has_many' => array_combine($ids, $ids)]); return $form; }
function getForm() { $form = new LaraForm($this->relation); $form->putTbHidden('relation')->setValue($this->relation); $method = \Str::camel('relation_' . $this->relation); $model = call_user_func([$this, $method]); $options = $model::orderBy($this->orderByModel())->listsExt(); if (!is_array($options)) { $options = []; } $method = \Str::camel('empty_' . $this->relation); if (method_exists($this, $method)) { $empty = call_user_func([$this, $method]); $options = [0 => $empty] + $options; } $form->putTbGroupRadio('belongs_to', $options, false); $ids = $this->ids(); $form->initValues(['belongs_to' => $ids]); return $form; }
/** * Фильтр: диапазон чисел * * @param $form_field * @param $label * @param null $db_field */ function addFilterRangeNumericSlider($form_field, $label, $min = null, $max = null, $db_field = null) { if (!$db_field) { $db_field = $form_field; } larastatic('bootstrap-slider'); $value = \Input::get($form_field, $min . ',' . $max); $el = $this->form->putTbSlider($form_field)->setLabel($label)->setValue($value)->setOptionMax($max)->setOptionMin($min); $gr = $this->form->putTbGroup()->setAttribute('rel', $el->getId())->addClass('js-slider-group'); $from_name = 'from_' . $form_field; $to_name = 'to_' . $form_field; $gr->putTbInt($from_name)->setWrapClass('col-md-6')->addClass('js-slider-min'); $gr->putTbInt($to_name)->setWrapClass('col-md-6')->addClass('js-slider-max'); $values = explode(',', $value); $this->form->initValues([$from_name => Arr::get($values, 0), $to_name => Arr::get($values, 1)]); \LaraJs::addInline(''); $value = \Input::get($form_field); if ($value) { $values = explode(',', $value); $values = $this->ids($values); $this->model->whereBetween($db_field, $values); } }