public function testMergeIntoSelf() { $tag = Tag::firstOrCreate(['name' => 'Tag 1']); $this->assertSame(1, Tag::count()); $tag->merge($tag); $this->assertSame(1, Tag::count()); }
/** * Add some new tags by ajax. * * @param Request $request */ public function ajaxAddTags(Request $request) { $newTags = $request->input('new_tags', []); foreach ($newTags as $newTag) { $tag = Tag::firstOrCreate(['name' => $newTag]); } echo "添加成功!"; }