public function run() { $this->truncateTable('taggables'); $faker = Faker::create(); $tagIds = Tag::lists('id'); $contactIds = Contact::lists('id'); for ($i = 0; $i < 40; $i++) { DB::table('taggables')->insert(['tag_id' => $faker->randomElement($tagIds), 'taggable_id' => $faker->randomElement($contactIds), 'taggable_type' => Contact::class]); } }
/** * Update the specified resource in storage. * * @param UpdateTagRequest $request * @param int $id * @return \Symfony\Component\HttpFoundation\Response */ public function update(UpdateTagRequest $request, $id) { $tag = Tag::findOrFail($id); $data = ['name' => $request->json('name'), 'slug' => $request->json('slug'), 'description' => $request->json('description')]; foreach ($data as $name => $value) { if (!is_null($value)) { $tag->{$name} = $value; } } $tag->save(); return $this->respondWithItem($tag, new TagTransformer()); }
public function run() { $this->truncateTable('tags'); Tag::create(['name' => 'Sports', 'slug' => 'sports', 'description' => 'Related to sports or athletics.']); Factory::times(20)->create(Tag::class); }
/** @test */ public function it_updates_a_tag() { $data = ['name' => 'Test tag 2']; $response = $this->call('PUT', 'api/tags/1', [], [], [], $this->headers, json_encode($data)); $content = json_decode($response->getContent()); $updatedTag = \SevenShores\Kraken\Tag::find(1); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals($data['name'], $content->name); $this->assertEquals($data['name'], $updatedTag->name); }