Skip to content

Commit d0abf47

Browse files
authored
Merge pull request #2 from thedevdojo/fixing/BladeRender
Adding fixes to blade render
2 parents 5f165da + 8b552c1 commit d0abf47

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Tails.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ private function replaceBladeHTMLWithBladeDirectives($string){
8888
$string = str_replace('<ifGuest>', '@guest', $string);
8989
$string = str_replace('</ifGuest>', '@endguest', $string);
9090

91+
// trim any curly brace from {{ array.item }} to {{ $array->item }}
92+
$bladeCurlyBraceMatches = [];
93+
preg_match_all('/{{(.*?)}}/', $string, $bladeCurlyBraceMatches);
94+
foreach($bladeCurlyBraceMatches[1] as $index => $curlyBrace){
95+
$trimmedContent = trim($curlyBrace);
96+
// dd($trimmedContent[0]);
97+
if(isset($trimmedContent[0])){
98+
// if it's a string we don't replace it
99+
if($trimmedContent[0] != "'" && $trimmedContent[0] != '"'){
100+
$outputVariable = str_replace('.', '->', $trimmedContent);
101+
$string = str_replace($bladeCurlyBraceMatches[0][$index], '{{ $' . $outputVariable . '}}', $string);
102+
}
103+
}
104+
}
105+
91106
return $string;
92107
}
93108

src/TailsServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public function boot()
5858
$response = Tails::getResponse($projectURL);
5959
$data = Tails::getDataFromResponse($key, $response);
6060

61-
$data = str_replace('"', '\"', $data);
62-
return '<?php echo \Blade::render("' . $data . '"); ?>';
61+
return \Blade::render($data);
6362
});
6463

6564
}

0 commit comments

Comments
 (0)