caffeinated/modules

Call to undefined function Caffeinated\Modules\Repositories\str_slug() in Laravel 6.0

ly-dev opened this issue ยท 5 comments

Hi,

Tried to install in Laravel 6.0
composer require caffeinated/modules

It causes an error: Call to undefined function Caffeinated\Modules\Repositories\str_slug()

Laravel 6.0 doesn't have the help function str_slug(), see https://laravel.com/docs/6.0/helpers

Actually, from Laravel 5.7, it changes to Str::slug

use Illuminate\Support\Str;
$slug = Str::slug('Laravel 5 Framework', '-');

Below, the detail error dump.

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Symfony\Component\Debug\Exception\FatalThrowableError  : Call to undefined function Caffeinated\Modules\Repositories\str_slug()

  at /mnt/workspace/laravel60/vendor/caffeinated/modules/src/Repositories/LocalRepository.php:306
    302|         if (!$this->files->isDirectory(storage_path("app/modules"))) {
    303|             $this->files->makeDirectory(storage_path("app/modules"));
    304|         }
    305| 
  > 306|         $location = str_slug($this->location);
    307| 
    308|         return storage_path("app/modules/$location.json");
    309|     }
    310| }

  Exception trace:

  1   Caffeinated\Modules\Repositories\LocalRepository::getCachePath()
      /mnt/workspace/laravel60/vendor/caffeinated/modules/src/Repositories/LocalRepository.php:269

  2   Caffeinated\Modules\Repositories\LocalRepository::getCache()
      /mnt/workspace/laravel60/vendor/caffeinated/modules/src/Repositories/LocalRepository.php:14

Is it possible to fix this? Thx a lot!

A similar error is Call to undefined function Caffeinated\Modules\Repositories\studly_case().

studly_case() should be replaced by Str::studly()

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Symfony\Component\Debug\Exception\FatalThrowableError  : Call to undefined function Caffeinated\Modules\Repositories\studly_case()

  at /mnt/workspace/sbyongphp7_careai_ws_20190327115905/vendor/caffeinated/modules/src/Repositories/Repository.php:125
    121|      * @return string
    122|      */
    123|     public function getModulePath($slug)
    124|     {
  > 125|         $module = studly_case($slug);
    126| 
    127|         if (\File::exists($this->getPath()."/{$module}/")) {
    128|             return $this->getPath()."/{$module}/";
    129|         }

  Exception trace:

  1   Caffeinated\Modules\Repositories\Repository::getModulePath("Account")
      /mnt/workspace/sbyongphp7_careai_ws_20190327115905/vendor/caffeinated/modules/src/Repositories/Repository.php:145

  2   Caffeinated\Modules\Repositories\Repository::getManifestPath("Account")
      /mnt/workspace/sbyongphp7_careai_ws_20190327115905/vendor/caffeinated/modules/src/Repositories/Repository.php:78

I use below workaround to make the package working.

in bootstrap\app.php add below functions

use Illuminate\Support\Str;

if (!function_exists('str_slug')) {
    function str_slug($title, $separator = '-', $language = 'en')
    {
        return Str::slug($title, $separator, $language);
    }
}

if (!function_exists('studly_case')) {
    function studly_case($value)
    {
        return Str::studly($value);
    }
}

Add composer require laravel/helpers everything works.

I'll be sure to get this patched so you don't need to pull in the helpers package ๐Ÿ‘

Fixed in v6.0.0