【问题标题】:Laravel whoops and class str not foundLaravel 哎呀和类 str 未找到
【发布时间】:2019-03-03 22:03:11
【问题描述】:

我尝试将我的 Laravel 从 5.4 更新到 5.5,但我遇到了一些错误-

未捕获的错误:调用未定义的方法 Whoops\Handler\PrettyPageHandler::setApplicationPaths() in...

Laravel 日志显示类似这样的内容-

production.ERROR: Class 'str' not found {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(代码:0): 找不到类“str” C:\xampp\htdocs\teste\config\cache.php:91) [堆栈跟踪]

production.ERROR: Class 'str' not found {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(代码:0): 找不到类“str” C:\xampp\htdocs\teste\config\cache.php:91) [堆栈跟踪]

这就是我的 cache.php 的样子-

'prefix' => env(
    'CACHE_PREFIX',
    str::slug(env('APP_NAME', 'laravel'), '_').'_cache'
 ),

第 91 行是 str::slug。知道我错过了什么吗?

【问题讨论】:

  • 您是否按照官方的升级指南进行操作? laravel.com/docs/5.5/upgrade#upgrade-5.5.0
  • 是的,先生。还有 youtube 上的教程,我仍然想念这个:$
  • 你跑composer update了吗?
  • 是的,我有,现在我尝试清理缓存,例如,在缓存行 91 class str not found 中给出错误
  • 请尝试将str::slug 更改为str_slug

标签: php laravel


【解决方案1】:

您需要像其中之一一样更改字符串函数调用-

str_slug('your_string');

或者这个

use Str;

Str::slug('your_string');

确保在您对配置文件进行更改后运行此程序,以便您的配置更改可以再次缓存并按预期工作-

php artisan config:cache

【讨论】:

    【解决方案2】:

    要在刀片模板中使用Str,您可以添加到app.php

    class_alias('Illuminate\Support\Str', 'Str');
    

    或者对于config/app.php中的新版本别名部分

    'Str' => Illuminate\Support\Str::class,
    

    {{ Str::slug('your_string') }} 可用/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多