Laravel Custom Helpers

Custom Helpers

ComeOnOliver Updated 61 repo stars

File contents

Custom Helpers

Create a helper file

// app/Support/helpers.php
function money(int $cents): string { return number_format($cents / 100, 2); }

Autoload

Add to composer.json:

{
  "autoload": { "files": ["app/Support/helpers.php"] }
}

Run composer dump-autoload.

Guidelines

  • Keep helpers small and pure; avoid hidden IO/state
  • Prefer static methods on value objects when domain-specific

ComeOnOliver/skillshub/tree/main/skills/noartem/skills/laravel-custom-helpers commit 9e41a9f9a3

Frequently asked questions

npx skillmds@latest add comeonoliver/laravel-custom-helpers