str_slug() and the other str_ and array_ helpers are gone after upgrading Laravel
Call to undefined function str_slug()Short answer
Laravel 6 removed every global str_ and array_ helper from the framework, so str_slug() does not exist in Laravel 12. Replace each call with the Illuminate\Support\Str class, here Str::slug(). If a package you cannot edit still calls the old function, install laravel/helpers, which brings the old helpers back.
Fix it fast
1Find out which cause you have
Find every call of the removed helpers, first in your own code and then in the packages. A stack trace that ends in vendor/ points at a package. One that ends in app/ or a Blade view points at your code.
grep -rn "str_slug(" app/ resources/ routes/ database/ config/ grep -rl "str_slug(" vendor/ --include=*.php2Match what you see, then jump to its fix
What does the error look like?
Call to undefined function str_slug()Call to undefined function array_get()
Cause 1 of 2
Your own code still calls str_slug() or another removed helper
1Check
The Laravel 6 upgrade guide says all str_ and array_ helpers were moved to the laravel/helpers package and removed from the framework. A call that comes from your code has to change, or be covered by that package.
grep -rnE "str_slug\(|array_get\(" app/ resources/views/ routes/ database/2Fix
Use the Str and Arr classes the guide names. For slugs that is Str::slug(). In a Blade view, write the full class name, or use the str() helper and its slug method.
use Illuminate\Support\Str;
// before
$slug = str_slug($title, '-');
$value = array_get($data, 'user.name');
// after
$slug = Str::slug($title, '-');
$value = \Illuminate\Support\Arr::get($data, 'user.name');
// in Blade, without an import
{{ \Illuminate\Support\Str::slug($post->title) }}
// fluent form
$slug = str($title)->slug('-');3Verify
Run the page or command that failed. The slug comes out in lower case with hyphens.
// in php artisan tinker
>>> Illuminate\Support\Str::slug('Laravel 5 Framework', '-');
=> "laravel-5-framework"Confirmed by raw.githubusercontent.com
Cause 2 of 2
A package in vendor/ calls the removed helper
1Check
A package written for an older Laravel may still call str_slug() or array_get(). The grep over vendor/ in the first step lists those files.
grep -rl "str_slug(" vendor/ --include=*.php2Fix
Update the package to a version that supports your Laravel version. If none exists, install laravel/helpers, a compatibility layer for the old helpers, and your code and the package both work again.
composer require laravel/helpers3Verify
Composer lists the package, and the request that failed now works.
composer show laravel/helpersConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Prefer the Str and Arr classes in new code, so no upgrade ever depends on global helper functions.
- Before upgrading, search for str_ and array_ calls and replace them in the same change as the framework bump.
- Run the test suite and the main pages after each major Laravel upgrade, because an undefined function only fails when its line runs.
- Add laravel/helpers only as a stopgap and remove it once the code and its packages no longer need it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix