/** * @test */ public function a_posts_tags_can_be_synced_by_posting_to_an_api_endpoint() { $post = factory(Post::class)->create(); $this->withoutMiddleware(); $response = $this->call('POST', '/admin/api/posts/' . $post->id . '/tags', ['tags' => ['health', 'wealth', 'stealth']]); $this->assertEquals(200, $response->status()); $post = Post::findOrFail($post->id); $this->assertEquals(['health', 'wealth', 'stealth'], $post->tags->pluck('tag')->toArray()); }
/** * @test */ public function syncing_tags_overrides_old_ones() { $tagIds1 = $this->getIdsOfCreatedTags(3); $tagIds2 = $this->getIdsOfCreatedTags(3); $post = factory(Post::class)->create(); $post->syncTags($tagIds1); $oldTags = $post->tags; $post->syncTags($tagIds2); $post = Post::findOrFail($post->id); //refresh post instance $newTags = $post->tags; $this->assertFalse($newTags->contains($oldTags->last())); $this->assertFalse($newTags->contains($oldTags->first())); $this->assertCount(3, $newTags); }
/** * @test */ public function a_posts_published_at_date_is_set_when_it_is_first_published() { $post = factory(Post::class)->create(); $post->setPublishedStatus(true); $this->assertEquals(Carbon::now()->toFormattedDateString(), Post::findOrFail($post->id)->published_at->toFormattedDateString()); }
public function archivedPost($id) { $post = Post::where('archive_id', $id)->firstOrFail(); return view('front.blog.post')->with(compact('post')); }
public function getTags($id) { $tags = Post::with('tags')->findOrFail($id)->tags->pluck('tag')->toArray(); return response()->json(['tags' => $tags]); }