From 8b552c1fc1d6e6a84f15a6ce89e5293ae1efad33 Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Sat, 20 Aug 2022 08:27:02 -0400 Subject: [PATCH] Adding fixes to blade render --- src/Tails.php | 15 +++++++++++++++ src/TailsServiceProvider.php | 3 +-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Tails.php b/src/Tails.php index dde13d4..6e4587c 100644 --- a/src/Tails.php +++ b/src/Tails.php @@ -88,6 +88,21 @@ private function replaceBladeHTMLWithBladeDirectives($string){ $string = str_replace('', '@guest', $string); $string = str_replace('', '@endguest', $string); + // trim any curly brace from {{ array.item }} to {{ $array->item }} + $bladeCurlyBraceMatches = []; + preg_match_all('/{{(.*?)}}/', $string, $bladeCurlyBraceMatches); + foreach($bladeCurlyBraceMatches[1] as $index => $curlyBrace){ + $trimmedContent = trim($curlyBrace); + // dd($trimmedContent[0]); + if(isset($trimmedContent[0])){ + // if it's a string we don't replace it + if($trimmedContent[0] != "'" && $trimmedContent[0] != '"'){ + $outputVariable = str_replace('.', '->', $trimmedContent); + $string = str_replace($bladeCurlyBraceMatches[0][$index], '{{ $' . $outputVariable . '}}', $string); + } + } + } + return $string; } diff --git a/src/TailsServiceProvider.php b/src/TailsServiceProvider.php index f4774b7..8d17953 100644 --- a/src/TailsServiceProvider.php +++ b/src/TailsServiceProvider.php @@ -58,8 +58,7 @@ public function boot() $response = Tails::getResponse($projectURL); $data = Tails::getDataFromResponse($key, $response); - $data = str_replace('"', '\"', $data); - return ''; + return \Blade::render($data); }); }