Weave Code
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

Support Laravel Package

illuminate/support

View on GitHub
Deep Wiki
Context7

Getting Started

The illuminate/support package is foundational to Laravel and provides essential helper classes, functions, and utilities used daily by developers. It’s not meant to be used in isolation but is automatically included when you install Laravel. To start leveraging it:

  • Ensure you have Laravel installed (laravel new app or use an existing Laravel project).
  • Install via Composer if needed: composer require illuminate/support.
  • The package re-exports core traits and helpers (e.g., Str, Arr, Optional, SnakeCase, CamelCase) globally and via facades.
  • First use case: use Str::slug('Hello World!') or Arr::divide(['foo' => 'bar']) anywhere in your app — these helpers are auto-loaded.

Check the Laravel documentation on helpers for immediate, common use cases.

Implementation Patterns

  • Collection Usage: Use collect() helper with methods like map, filter, pipe, and tap for chaining data transformations.
    $result = collect($users)
        ->map(fn($u) => $u->name)
        ->filter(fn($name) => strlen($name) > 3)
        ->values();
    
  • Conditional Chaining: Leverage the Conditionable trait (used in Str, Arr, etc.) for fluent conditionals.
    return Str::of($slug)
        ->when($appendId, fn($str) => $str->append('-' . $id))
        ->when($uppercase, fn($str) => $str->upper());
    
  • Macroable Patterns: Extend core classes like Str, Arr, or custom classes using Macroable.
    Str::macro('reverseWords', fn($string) => implode(' ', array_reverse(explode(' ', $string))));
    echo Str::reverseWords('one two three'); // "three two one"
    
  • Value Objects & Utilities: Use Optional for null-safe access, Str for multibyte string manipulation, and Str::of() for fluent string operations.

Gotchas and Tips

  • Macro Conflicts: Avoid naming macros the same as existing methods — they’ll silently override them. Consider namespacing macros or using prefixes.
  • Case Sensitivity & Multibyte: Str methods respect multibyte (via mbstring), but array_* helpers (e.g., array_camel_case) don’t exist — use Arr::camel() instead.
  • Lazy Collections: While LazyCollection lives in illuminate/support, it’s only useful when chaining large datasets (e.g., from DB queries). Use LazyCollection::make(fn() => $generator) to avoid memory bloat.
  • Auto-loading Helpers: These functions are auto-loaded via helpers.php — don’t call require manually. Avoid aliasing core helpers in namespaces.
  • Breaking Changes: Even minor updates may tweak Str or Arr behavior (e.g., new flags in Str::plural()). Check release notes for breaking changes.
  • Debugging Tip: Use dump($collection) or dd(Str::of($str)->trim()->slug()) to inspect intermediate values in chains — Laravel’s dd understands these objects well.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport