Replies: 2 comments 1 reply
-
I define the macro with use Spatie\Html\Html class, within the boot method of App\Providers\AppServiceProvider class: use Money\Money;
use Spatie\Html\Html;
Html::macro('money', function (string $name, string|Money $value = null) {
/** @var \Spatie\Html\Html $this */
$value = $this->value($name, $value);
if ($value instanceof Money) {
$value = $value->getAmount();
}
return $this->text($name, $value);
}); and calling in blade files with this {{ html()->money('amount') }} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Instead of using Macros, you could use a Mixin. It's basically the same as defining a Marco, but you'll will be able to extend a class as well. Both have advances and disadvantages. I prefer a Mixin when I really need to extend multiple things at once. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I want to create custom element which I'll use Bootstrap/TailwindCss class for form group, I did not find a way to create a macro in the documentation
Beta Was this translation helpful? Give feedback.
All reactions