private function addTaxonomy($categories, $model) { if (!is_array($categories)) { $categories = [$categories]; } foreach ($categories as $key => $category) { $taxonomy = Taxonomy::where('title', '=', $category)->first(); // echo $category . "\n"; if (is_null($taxonomy)) { $taxonomy = Taxonomy::create(['title' => $category, 'model' => get_class($model)]); } if (!is_null($taxonomy)) { $model->taxonomy()->add($taxonomy, null); } } }
public static function getCategories() { $categories = TaxonomyModel::where('model', get_class())->select('id', 'title', 'slug')->get(); // CW::info($categories); return $categories; }