Skip to content

Commit d79cbed

Browse files
Prevent issue when empty scripts and styles
1 parent 82210d4 commit d79cbed

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Assets.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,17 @@ public function addScriptsDirectly($assets, $location = self::ASSETS_SCRIPT_POSI
146146
*/
147147
public function removeStyles($assets)
148148
{
149+
if (empty($this->styles)) {
150+
return $this;
151+
}
152+
149153
foreach ((array)$assets as $rem) {
150-
Arr::forget($this->styles, array_search($rem, $this->styles));
154+
$index = array_search($rem, $this->styles);
155+
if ($index === false) {
156+
continue;
157+
}
158+
159+
Arr::forget($this->styles, $index);
151160
}
152161

153162
return $this;
@@ -161,8 +170,17 @@ public function removeStyles($assets)
161170
*/
162171
public function removeScripts($assets)
163172
{
173+
if (empty($this->scripts)) {
174+
return $this;
175+
}
176+
164177
foreach ((array)$assets as $rem) {
165-
Arr::forget($this->scripts, array_search($rem, $this->scripts));
178+
$index = array_search($rem, $this->scripts);
179+
if ($index === false) {
180+
continue;
181+
}
182+
183+
Arr::forget($this->scripts, $index);
166184
}
167185

168186
return $this;

0 commit comments

Comments
 (0)