protected function collectFilteredAttributes($id) { $a = array(); if (count($id) > 1) { foreach ($id as $k => $filter) { if ($k <= 0 || $filter <= 0) { continue; } // skip category $a[$k] = \Veer\Models\Attribute::find($filter)->toArray(); } } return $a; }
/** * Delete attribute * */ protected function deleteAttribute($id) { $t = \Veer\Models\Attribute::find($id); if (is_object($t)) { $t->pages()->detach(); $t->products()->detach(); $t->delete(); return true; } return false; }
/** * Update Attributes Connections * @todo Test */ protected function attachToAttributes($name, $form) { $new = $this->parseForm($form); if (!is_array($new['target'])) { return null; } foreach ($new['target'] as $a) { $a = trim($a); if (empty($a)) { continue; } if (starts_with($a, ":")) { // id $aDb = \Veer\Models\Attribute::find(substr($a, 1)); if (!is_object($aDb)) { continue; } } else { // string values $aDb = \Veer\Models\Attribute::firstOrNew(['name' => $name, 'val' => $a]); $aDb->type = empty($aDb->type) ? 'descr' : $aDb->type; $aDb->descr = empty($aDb->descr) ? '' : $aDb->descr; $aDb->save(); } $attributes[] = $aDb->id; } if (isset($attributes)) { $this->attachFromForm($new['elements'], $attributes, 'attributes'); } }