84

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()

Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
Soft Technoes
  • 1,065
  • 1
  • 7
  • 18
  • 7
    `str_slug()` is not available in `6.0`. They have changed it to `Str::slug`. Looks like some of your Laravel code is still from `5.8` – Cerlin Sep 10 '19 at 05:54
  • problem solved... Thanks :) – Soft Technoes Sep 10 '19 at 06:12
  • 1
    I have the same issue, but the str_slug is from the cache.php and session.php files supplied by laravel. How do I get more recent versions of these files? – mankowitz Oct 19 '19 at 13:25
  • when you update your project into 6.0 these files will be automatic updated at their location if not available then will be created. Run `composer update` from your terminal – Soft Technoes Oct 21 '19 at 05:07
  • 3
    I had the same problem as mankowitz, but composer update didn't update them. I went on the github of laravel to get the latest code and updated confg/cache.php and config/session.php manually. – Jack Wire Jan 22 '20 at 11:36

6 Answers6

154

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

leymannx
  • 5,138
  • 5
  • 45
  • 48
ManojKiran A
  • 5,896
  • 4
  • 30
  • 43
  • hi. i have the same problem. after `composer require laravel/helpers` the problem didn't solved. is there any thing i must do? – E.B Oct 22 '19 at 07:00
  • is it a fresh installation of laravel 6.0 or Upgraded to 6.0 ?? – ManojKiran A Oct 22 '19 at 07:38
  • It's about upgrade to 6.0 – Soft Technoes Oct 31 '19 at 03:54
  • I was struggling by using Str_plural, then realized in 6* it has to be Str::_plural, but that was still not working but by installing the laravel/helpers package, and clearing the artisan cache/config etc... it worked perfectly. Thank you. – CodeConnoisseur Jan 25 '20 at 15:11
40

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', '-');
Masood Khan
  • 587
  • 3
  • 8
2

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)

user3719458
  • 346
  • 3
  • 12
2

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);
}
Krina Mangukiya
  • 366
  • 2
  • 7
0

$post = Post::create([ 'slug' => S t r::slug($request->title), here we go

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 26 '22 at 07:09
-1

composer require laravel/helpers

php artisan optimize:clear

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 08 '22 at 17:51