From a7f1752be39532340312c0ce4ff40add2b56b66f Mon Sep 17 00:00:00 2001 From: charlesteh <39686678+charlesteh@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:59:43 +0800 Subject: [PATCH] Update Post.php --- app/Models/Post.php | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/app/Models/Post.php b/app/Models/Post.php index 792364d..e5fc32c 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -152,29 +152,36 @@ public function getHtmlBodyAttribute() } }); - // Modify the DOM by wrapping the tags inside a
and adding the desired structure - $crawler->filter('img')->each(function (Crawler $node) { - $imgElement = $node->getNode(0); + // Modify the DOM by wrapping the tags inside a
and adding the desired structure + $crawler->filter('img')->each(function (Crawler $node) { + $imgElement = $node->getNode(0); + + // Update the class of the + $existingClasses = $imgElement->getAttribute('class'); + $newClasses = 'img-fluid rounded-2 shadow-sm mb-2'; + $updatedClasses = ($existingClasses ? $existingClasses.' ' : '').$newClasses; + $imgElement->setAttribute('class', $updatedClasses); + + // Create a new
element + $figureElement = new \DOMElement('figure'); + $imgElement->parentNode->insertBefore($figureElement, $imgElement); + + // Move the inside the
+ $figureElement->appendChild($imgElement); + $figureElement->setAttribute('class', 'image'); + + // Create a new