public function test_can_search_tags() { //create two tag to show up and one to not show $tagA = factory(Tag::class)->make(['title' => 'easel', 'tag' => 'easel']); $tagB = factory(Tag::class)->make(['title' => 'Easel', 'subtitle' => 'easel']); $tagC = factory(Tag::class)->make(['tag' => 'this shouldnt show up', 'title' => 'this-shouldnt-show-up', 'meta_description' => 'this-shouldnt-show-up', 'subtitle' => 'this-shouldnt-show-up']); $tagA->save(); $tagB->save(); $tagC->save(); $tags = Tag::whereIn('id', [$tagA->id, $tagB->id])->get(); //$tags = Tag::search('easel')->get(); $response = $this->actingAs($this->user)->call('GET', '/admin/search?search=easel'); $this->assertEquals(200, $response->status()); $this->assertViewHas('tags', $tags); }
/** * Sync tag relationships and add new tags as needed. * * @param array $tags */ public function syncTags(array $tags) { Tag::addNeededTags($tags); if (count($tags)) { $this->tags()->sync(Tag::whereIn('tag', $tags)->pluck('id')->all()); return; } $this->tags()->detach(); }