Skip to content

Commit

Permalink
Merge pull request #28129 from kylekatarnls/allow-non-string-return-d…
Browse files Browse the repository at this point in the history
…ate-macro

[5.8] Allow to call macros directly on Date
  • Loading branch information
taylorotwell authored Apr 8, 2019
2 parents 58360ff + 7621ba1 commit b699e5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Illuminate/Support/DateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public function __call($method, $parameters)
$dateClass = static::$dateClass ?: $defaultClassName;

// Check if date can be created using public class method...
if (method_exists($dateClass, $method)) {
if (method_exists($dateClass, $method) ||
method_exists($dateClass, 'hasMacro') && $dateClass::hasMacro($method)) {
return $dateClass::$method(...$parameters);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Support/DateFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ public function testUseInvalidHandler()

DateFactory::use(42);
}

public function testMacro()
{
Date::macro('returnNonDate', function () {
return 'string';
});

$this->assertSame('string', Date::returnNonDate());
}
}

0 comments on commit b699e5e

Please sign in to comment.