Skip to content

Commit

Permalink
Merge pull request #2 from thedevdojo/fixing/BladeRender
Browse files Browse the repository at this point in the history
Adding fixes to blade render
  • Loading branch information
tnylea authored Aug 20, 2022
2 parents 5f165da + 8b552c1 commit d0abf47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/Tails.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ private function replaceBladeHTMLWithBladeDirectives($string){
$string = str_replace('<ifGuest>', '@guest', $string);
$string = str_replace('</ifGuest>', '@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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/TailsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function boot()
$response = Tails::getResponse($projectURL);
$data = Tails::getDataFromResponse($key, $response);

$data = str_replace('"', '\"', $data);
return '<?php echo \Blade::render("' . $data . '"); ?>';
return \Blade::render($data);
});

}
Expand Down

0 comments on commit d0abf47

Please sign in to comment.