Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 6bf3fda

Browse files
committed
Make compatible for Laravel 8.0 - 8.26
1 parent d92366e commit 6bf3fda

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/FormComponentsServiceProvider.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rawilk\FormComponents;
66

7+
use Illuminate\Support\Arr;
78
use Illuminate\Support\Facades\Blade;
89
use Illuminate\Support\Facades\Route;
910
use Illuminate\Support\ServiceProvider;
@@ -102,6 +103,26 @@ private function bootMacros(): void
102103
ComponentAttributeBag::macro('hasStartsWith', function ($key) {
103104
return (bool) $this->whereStartsWith($key)->first();
104105
});
106+
107+
// Add backwards support for Laravel 8.0 - 8.26.
108+
// This macro can be removed if we ever deprecate those versions.
109+
if (! method_exists(ComponentAttributeBag::class, 'class')) {
110+
ComponentAttributeBag::macro('class', function ($classList) {
111+
$classList = Arr::wrap($classList);
112+
113+
$classes = [];
114+
115+
foreach ($classList as $class => $constraint) {
116+
if (is_numeric($class)) {
117+
$classes[] = $constraint;
118+
} elseif ($constraint) {
119+
$classes[] = $class;
120+
}
121+
}
122+
123+
return $this->merge(['class' => implode(' ', $classes)]);
124+
});
125+
}
105126
}
106127

107128
private function bootRoutes(): void

0 commit comments

Comments
 (0)