$chapter->unsetRelations()->refresh();
$chapter->load(['tags']);
- $chapter->makeVisible('description_html')
- ->setAttribute('description_html', $chapter->descriptionHtml());
+ $chapter->makeVisible('description_html');
+ $chapter->setAttribute('description_html', $chapter->descriptionHtml());
+ $chapter->setAttribute('book_slug', $chapter->book()->first()->slug);
return $chapter;
}
$resp = $this->getJson($this->baseEndpoint . '?count=1&sort=+id');
$resp->assertJson(['data' => [
[
- 'id' => $firstChapter->id,
- 'name' => $firstChapter->name,
- 'slug' => $firstChapter->slug,
- 'book_id' => $firstChapter->book->id,
- 'priority' => $firstChapter->priority,
+ 'id' => $firstChapter->id,
+ 'name' => $firstChapter->name,
+ 'slug' => $firstChapter->slug,
+ 'book_id' => $firstChapter->book->id,
+ 'priority' => $firstChapter->priority,
+ 'book_slug' => $firstChapter->book->slug,
],
]]);
}
$resp->assertJson([
'id' => $chapter->id,
'slug' => $chapter->slug,
+ 'book_slug' => $chapter->book->slug,
'created_by' => [
'name' => $chapter->createdBy->name,
],
],
],
]);
+ $resp->assertJsonMissingPath('book');
$resp->assertJsonCount($chapter->pages()->count(), 'pages');
}