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.
Installation:
composer require laravel/helpers
No additional configuration is required—helpers are immediately available globally.
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');
Where to Look First:
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);
Gradual Migration:
deprecation facade or custom middleware).array_get → Arr::get).Integration with Modern Laravel:
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');
Testing:
array_first on empty arrays) with the package’s fixes applied.Laravel 5.8 → [Install helpers package] → Laravel 12 → [Refactor legacy helpers] → Laravel 13+
Html::decode()).grep -r "array_add\|str_limit\|Arr::dot" app/ --include="*.php"
AppServiceProvider:
use Illuminate\Support\Facades\Arr;
use Illuminate\Support\Facades\Str;
// No action needed; package auto-registers facades.
False Sense of Security:
php artisan vendor:publish --tag=laravel-legacy.Performance Overhead:
Infinite Loops:
array_first, array_last, and str_contains (fixed in v1.8.0+).composer update laravel/helpers
PHP Version Mismatches:
Deprecation Warnings:
error_reporting(E_ALL & ~E_DEPRECATED);
composer dump-autoload
Arr::add() behaves unexpectedly, check for custom facade bindings:
php artisan package:discover
str_limit(null, 10)).Arr, Str, or Html facades in your app’s config/app.php to prevent conflicts.class LegacyHelper {
public static function old_helper($input) {
return \Illuminate\Support\Arr::get($input, 'path');
}
}
use Illuminate\Support\Facades\Deprecator;
Deprecator::warning('Legacy helper used: array_add', ['helper' => 'array_add']);
$this->app->singleton('helpers', function () {
return new class {
public function __call($method, $args) {
return \Illuminate\Support\Arr::{$method}(...$args);
}
};
});
if (!function_exists('array_add')) {
function array_add(array &$array, $key, $value) {
Arr::set($array, $key, $value);
}
}
Arr::dot() Carefully:
The legacy Arr::dot() behavior differs slightly from modern implementations. Test with complex nested arrays.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
How can I help you explore Laravel packages today?