Skip to content

Commit bf18cfe

Browse files
committed
Merge pull request #2521 from yajra/closure-di
[9.x] Add support for dependency injection when using closure. (cherry picked from commit 3e6846a)
1 parent e703d86 commit bf18cfe

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Utilities/Helper.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,16 @@ public static function compileContent($content, array $data, array|object $param
6363
{
6464
if (is_string($content)) {
6565
return static::compileBlade($content, static::getMixedValue($data, $param));
66-
} elseif (is_callable($content)) {
66+
}
67+
68+
if (is_callable($content)) {
69+
$reflection = new \ReflectionFunction($content);
70+
$arguments = $reflection->getParameters();
71+
72+
if (count($arguments) > 0) {
73+
return app()->call($content, [$arguments[0]->name => $param]);
74+
}
75+
6776
return $content($param);
6877
}
6978

0 commit comments

Comments
 (0)