Skip to content

Commit 3e6846a

Browse files
authored
Merge pull request #2521 from yajra/closure-di
[9.x] Add support for dependency injection when using closure.
2 parents f49b1b0 + 731151f commit 3e6846a

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
@@ -61,7 +61,16 @@ public static function compileContent($content, array $data, $param)
6161
{
6262
if (is_string($content)) {
6363
return static::compileBlade($content, static::getMixedValue($data, $param));
64-
} elseif (is_callable($content)) {
64+
}
65+
66+
if (is_callable($content)) {
67+
$reflection = new \ReflectionFunction($content);
68+
$arguments = $reflection->getParameters();
69+
70+
if (count($arguments) > 0) {
71+
return app()->call($content, [$arguments[0]->name => $param]);
72+
}
73+
6574
return $content($param);
6675
}
6776

0 commit comments

Comments
 (0)