Laravel Error: “Call to undefined function str_slug()”

Posted by

Error:
In cache.php line 91: Call to undefined function str_slug() Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

If you’ve encountered the error “In cache.php line 91: Call to undefined function str_slug() Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1” in your Laravel project, This issue often arises when there are changes in Laravel versions, and some functions get deprecated. The error message indicates that there is an undefined function str_slug() at line 91 in the cache.php file. This commonly occurs after Laravel version upgrades when deprecated functions are no longer available.

Laravel Version Incompatibility: The str_slug() function has been deprecated and removed in later versions of Laravel.

Outdated Packages: Your Laravel project might be using third-party packages that haven’t been updated to support the latest Laravel version.

Solution

Update Laravel Version

Ensure that your Laravel project is using a version that is compatible with the codebase. Check your composer.json file for the Laravel version constraint and update it to a version that supports the functionality. You can find the latest version on the official Laravel GitHub repository.

“laravel/framework”: “your_latest_version”,

After updating the version constraint, run the following command to update your project:

composer update

You can install the package with the command if you still wish to use the helpful functions.

composer require laravel/helpers

 you can do it using the Laravel facade.

use Illuminate\Support\Str;
 
$stringslug = Str::slug('My Custom String Here');

Clear Cache

php artisan cache:clear

Refer to the Laravel release notes to identify any breaking changes or deprecated features between your current version and the version you’re updating to.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x