Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Helpers Laravel Package

ralphjsmit/laravel-helpers

Handy helpers for Laravel apps, including a Factory base class with resolveRelationship() for complex factory relations and a simple pipe implementation for passing data through sequential classes without closures. Great for cleaner factories and predictable pipelines.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require ralphjsmit/laravel-helpers. No service provider or config publishing is required—helpers are auto-loaded via the package’s helpers.php file (PSR-4 autoloading in src/Helpers). The first use case is typically replacing verbose conditional checks with helpers like present() (returns formatted value if not null) or blank_or() (returns fallback for null/blank values), e.g. present($user->email) ?? 'No email'.

Implementation Patterns

  • Inline formatting: Use present(), number(), currency(), or truncate() directly in Blade or controllers to avoid @if/else chains and keep templates concise.
  • Null-safe transformations: Replace ternary null-checks with blank_or($value, 'default') or filled_or($value, 'fallback').
  • Array/Collection shortcuts: Leverage array_get_path($array, 'user.profile.name') for nested access or array_only_keys($array, ['name', 'email']) for filtering without array_filter boilerplate.
  • Validation helpers: Integrate unique_without() (for validation rules excluding current model) directly in request validation.
  • Team consistency: Commit common helper usage in style guides—e.g., “always use starts_with($str, $prefix) instead of Str::startsWith() for brevity in internal code.”

Gotchas and Tips

  • Helpers are global functions—avoid naming conflicts with existing helpers (e.g., Laravel’s str_replace_first). This package extends Laravel helpers but doesn’t override them.
  • Some functions behave differently from PHP native equivalents: e.g., blank() considers 0, '0', '', and [] as blank, while empty() does not. Always check the docblock or tests if behavior is ambiguous.
  • Not all helpers support PHP 8.0–8.4 uniformly—review src/Helpers/ for signature compatibility (e.g., typed returns using |null/|false).
  • To extend: add custom helpers in app/helpers.php, but do not rely on this package for custom logic—reserve it for standardized small utilities only.
  • For debugging: use dd_safe() or dump_safe() to avoid issues with circular references or objects that can’t be serialized.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc