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

Helpers Laravel Package

laravel/helpers

Backwards-compatibility package that restores Laravel 5.8 global helper functions for newer Laravel versions. Useful when upgrading legacy apps; helpers map to modern Arr and Str methods. Not accepting new helpers.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require laravel/helpers
    

    No additional configuration is required—helpers are immediately available globally.

  2. First Use Case: Replace deprecated Laravel 5.8 helpers (e.g., array_add()) with their modern equivalents while maintaining compatibility:

    // Legacy (Laravel 5.8) - works with the package
    array_add($array, 'key', 'value');
    
    // Modern (Laravel 9+) - equivalent
    Arr::set($array, 'key', 'value');
    
  3. Where to Look First:

    • Official Laravel Docs: Arr, Str for modern alternatives.
    • Package Source: GitHub for edge-case fixes (e.g., array_first infinite loop patches).

Implementation Patterns

Usage Patterns

  1. Direct Replacement: Use legacy helper syntax in existing codebases without changes while upgrading Laravel versions:

    // Works in Laravel 12+ with the package
    $limited = str_limit('long string', 20);
    
  2. Gradual Migration:

    • Phase 1: Install the package and verify all legacy helpers work.
    • Phase 2: Log warnings when deprecated helpers are used (via deprecation facade or custom middleware).
    • Phase 3: Replace helpers incrementally (e.g., array_getArr::get).
  3. Integration with Modern Laravel:

    • Combine with Arr, Str, and Collection helpers for new development:
      // Legacy (compatible)
      $value = array_get($array, 'path.to.value');
      
      // Modern (preferred for new code)
      $value = Arr::get($array, 'path.to.value');
      
  4. Testing:

    • Use the package in staging environments to validate compatibility before full deployment.
    • Test edge cases (e.g., array_first on empty arrays) with the package’s fixes applied.

Workflows

  • Upgrade Path:
    Laravel 5.8 → [Install helpers package] → Laravel 12 → [Refactor legacy helpers] → Laravel 13+
    
  • Plugin/Third-Party Compatibility: Use the package to maintain compatibility with older plugins that rely on deprecated helpers (e.g., Html::decode()).

Integration Tips

  • IDE Support: Configure your IDE (PHPStorm/VSCode) to highlight deprecated helpers as warnings.
  • CI/CD: Add a linting step to detect legacy helper usage:
    grep -r "array_add\|str_limit\|Arr::dot" app/ --include="*.php"
    
  • Service Providers: Register the package’s aliases automatically in AppServiceProvider:
    use Illuminate\Support\Facades\Arr;
    use Illuminate\Support\Facades\Str;
    
    // No action needed; package auto-registers facades.
    

Gotchas and Tips

Pitfalls

  1. False Sense of Security:

    • The package only supports helpers, not other Laravel 5.8 features (e.g., deprecated Eloquent methods, Blade directives).
    • Fix: Audit for broader deprecations using php artisan vendor:publish --tag=laravel-legacy.
  2. Performance Overhead:

    • Legacy helpers may introduce minor runtime overhead due to compatibility wrappers.
    • Fix: Benchmark critical paths post-upgrade.
  3. Infinite Loops:

    • Early versions had issues with array_first, array_last, and str_contains (fixed in v1.8.0+).
    • Fix: Update to the latest package version:
      composer update laravel/helpers
      
  4. PHP Version Mismatches:

    • The package supports PHP 8.5 but may not work with older PHP versions (e.g., 7.4).
    • Fix: Align PHP version with Laravel’s requirements (e.g., Laravel 12 → PHP 8.1+).
  5. Deprecation Warnings:

    • Modern Laravel may still emit warnings for legacy helpers even with the package installed.
    • Fix: Suppress warnings temporarily during migration:
      error_reporting(E_ALL & ~E_DEPRECATED);
      

Debugging

  • Helper Not Found?: Ensure the package is installed and autoloaded. Run:
    composer dump-autoload
    
  • Facade Conflicts: If Arr::add() behaves unexpectedly, check for custom facade bindings:
    php artisan package:discover
    
  • Edge Cases: Test with nested arrays, empty inputs, and non-string values (e.g., str_limit(null, 10)).

Config Quirks

  • No Configuration File: The package is zero-config. All helpers are auto-registered via Laravel’s service provider.
  • Facade Overrides: Avoid overriding Arr, Str, or Html facades in your app’s config/app.php to prevent conflicts.

Extension Points

  • Custom Helpers: Extend the package by creating wrapper classes for unsupported helpers:
    class LegacyHelper {
        public static function old_helper($input) {
            return \Illuminate\Support\Arr::get($input, 'path');
        }
    }
    
  • Deprecation Logging: Hook into Laravel’s deprecation system to track legacy helper usage:
    use Illuminate\Support\Facades\Deprecator;
    
    Deprecator::warning('Legacy helper used: array_add', ['helper' => 'array_add']);
    
  • Testing: Mock legacy helpers in unit tests:
    $this->app->singleton('helpers', function () {
        return new class {
            public function __call($method, $args) {
                return \Illuminate\Support\Arr::{$method}(...$args);
            }
        };
    });
    

Pro Tips

  1. Alias Modern Helpers: Create shortcuts for modern equivalents to ease migration:
    if (!function_exists('array_add')) {
        function array_add(array &$array, $key, $value) {
            Arr::set($array, $key, $value);
        }
    }
    
  2. Use Arr::dot() Carefully: The legacy Arr::dot() behavior differs slightly from modern implementations. Test with complex nested arrays.
  3. Leverage Str::of(): Modern Str::of() handles null inputs gracefully—prefer it over str_limit for new code:
    Str::of(null)->limit(20); // Safe
    str_limit(null, 20);     // May throw errors
    
  4. Monitor for Removals: The package may drop support for helpers in future Laravel versions. Plan to refactor proactively.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai