public function testJsonableInterfaceImplementWithDifferentLang() { $this->assertTrue($this->createContent(3)); /* first */ $content = Content::find(1); $postFirst = ['__lang_id__' => 1, 'title' => 'First Title', 'content' => 'First Content']; $lang1 = $content->ContentLangs()->create($postFirst); $wrapper = $this->wrapper->createNew($content, 2); $attributes = array_merge($content->getAttributes(), $lang1->getAttributes()); $this->assertEquals($attributes, $wrapper->toArray()); $wrapper->toJson(); // not need to check!! // fixed!! }
/** * to create a lot of wrapper by using models in Eloquent Collection * * @param \Illuminate\Support\Collection $collection * @param \Illuminate\Database\Eloquent\Model|int $wantedLang language id or specific language model * @param \Illuminate\Database\Eloquent\Model|int $defaultLang language id or specific language model * @return \Illuminate\Support\Collection */ protected function createWrappersInCollection(Collection $collection, $wantedLang, $defaultLang) { $newCollection = new EloquentColl(); $tempCollection = new EloquentColl($collection->all()); while (!$tempCollection->isEmpty()) { $newCollection->add($this->wrapper->createNew($tempCollection->shift(), $wantedLang, $defaultLang)); } return $newCollection; }