From d56aebc9b828e364a361a00214c020943f4ce52e Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 10 Feb 2020 21:20:21 +0100 Subject: [PATCH] Don't crash when @stack['componentScripts'] is empty and properly format the output --- views/layout/default.blade.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 577bfa84..f236d9e4 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -479,20 +479,23 @@ $reflection = new \ReflectionClass($__env); $property = $reflection->getProperty('pushes'); $property->setAccessible(true); - - // Take every line into a new array, one element per line - $filteredStack = array_map(function($value) - { - return explode("#SEP#", str_replace(array("\n", "\r", "\t"), '#SEP#', trim($value))); - }, $property->getValue($__env)['componentScripts']); - - // Flatten the array into a single one, only keep unique lines, remove empty lines - $filteredStack = array_filter(array_unique(array_merge(...$filteredStack))); - - // Write it back $env = $property->getValue($__env); - $env['componentScripts'] = $filteredStack; - $property->setValue($__env, $env); + + if (array_key_exists('componentScripts', $env)) + { + // Take every line into a new array, one element per line + $filteredStack = array_map(function($value) + { + return explode("#SEP#", str_replace(array("\n", "\r", "\t"), '#SEP#', trim($value))); + }, $env['componentScripts']); + + // Flatten the array into a single one, only keep unique lines, remove empty lines, add a defined new line + $filteredStack = preg_filter('/$/', "\n", array_filter(array_unique(array_merge(...$filteredStack)))); + + // Write it back + $env['componentScripts'] = $filteredStack; + $property->setValue($__env, $env); + } @endphp @stack('componentScripts')