/** * @param array $terms * @param $taxonomy * @param int $parent * @param int $order */ public static function createTaxonomies(array $terms, $taxonomy, $parent = 0, $order = 0) { if (count($terms) === 0) { return; } // only keep terms with existing entries in terms table $terms = Term::whereIn('name', $terms)->pluck('name')->all(); // create taxonomy entries for given terms foreach ($terms as $term) { Taxonomy::firstOrCreate(['taxonomy' => $taxonomy, 'term_id' => Term::where('name', $term)->first()->id, 'parent' => $parent, 'sort' => $order]); } }