Skip to content

Commit

Permalink
Merge pull request #227 from OzanKurt/patch-1
Browse files Browse the repository at this point in the history
fix: `Marcoable` trait usage together with `Fluent` helper
  • Loading branch information
yajra authored Nov 18, 2024
2 parents 3d53a81 + 4009e9c commit e7ccbf4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Html/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,32 @@ public function align(string $align = 'button-left'): static

return $this;
}

/**
* Handle dynamic calls to the fluent instance or macroable methods.
*
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
// Check if the method is a macro (Macroable functionality).
if (static::hasMacro($method)) {
$macro = static::$macros[$method];

if ($macro instanceof Closure) {
$macro = $macro->bindTo($this, static::class);
}

return $macro(...$parameters);
}

// Fallback to Fluent behavior if it's not a macro.
$this->attributes[$method] = count($parameters) > 0 ? reset($parameters) : true;

return $this;
}
}

0 comments on commit e7ccbf4

Please sign in to comment.