For brevity, i have three tables with the following columns:
Categories -id -name -slug
Topics -id -name -slug -category_id
Subtopics -id -name -slug -topic_id
Calling the below get us a nicely nested JSON output..
$body = Category::with(['topic', 'topic.subtopic'])->get();
However, i want to get the absolute URL by appending it to each JSON property into Topics and Subtopics with concatenating all slugs into a new 'URL' attribute.
-URL attribute for Topics would be /category_slug/topic slug
-URL attribute for Subtopics would be /category_slug/topic slug/subtopic_slug