Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Call to undefined function str_slug()" in Laravel 6.0

I've upgraded my laravel 5.8 project to 6.0. It has upgraded successfully but when I'm trying to run the project or installing another package to my project it is giving me error named as "Call to undefined function str_slug()" in session.php. I don't know why....

Call to undefined function str_slug()

like image 822
Soft Technoes Avatar asked Sep 10 '19 05:09

Soft Technoes


4 Answers

If you have gone through the upgrade guide then you must know that

String and Array Helpers have been removed from Core Framework

So if if You need to still use the helper install the package

composer require laravel/helpers

and all the helpers are moved to this package

like image 178
ManojKiran Appathurai Avatar answered Nov 16 '22 00:11

ManojKiran Appathurai


String and Array helpers are removed from laravel 6.0 Core Framework

https://laravel.com/docs/6.0/upgrade#helpers

So if You need to still use the helper install the package

composer require laravel/helpers

Or you can use by Laravel facade

use Illuminate\Support\Str;
$slug = Str::slug('Laravel 5 Framework', '-');
like image 22
Masood Khan Avatar answered Nov 16 '22 01:11

Masood Khan


Personal I hard to do the following on Laravel 6 on the app Controllers add this use Illuminate\Support\Str; then something like this 'slug' => Str::slug($request->title)

like image 44
user3719458 Avatar answered Nov 16 '22 02:11

user3719458


There are two options to resolve the issue of call to undefined function str_slug().

1.You should run the command composer require laravel/helpers

Or another option is when you don't want to install packages then this below solution is the easy way to solve your issue and it is the best way.

2.You can use facades class

use Illuminate\Support\Str;

public function index(Request $request)
{
   $slug = Str::slug($request->name);
}
like image 24
Krina Mangukiya Avatar answered Nov 16 '22 02:11

Krina Mangukiya