方法IlluminateSupportStr::replace不存在
我在用:
- Laravel 版本:8.35.1
- PHP 版本:7.4.9
在 Tinker 和 Routing 上,我使用文档中的Str::replace()方法,但出现错误:
带有消息 Method IlluminateSupportStr::replace 的 BadMethodCallException 不存在。
示例 1:
root@c6dd4af63e3c:/var/www/html# php artisan tinker
Psy Shell v0.10.7 (PHP 7.4.9 — cli) by Justin Hileman
>>> IlluminateSupportStr::replace('8.x', '9.x', 'Laravel 8.x');
BadMethodCallException with message 'Method IlluminateSupportStr::replace does not exist.'
>>>
示例2:
Route::get('/test', function () {
return IlluminateSupportStr::replace('8.x', '9.x', 'Laravel 8.x');
});
为什么会出现此错误以及如何解决?
回答
IlluminateSupportStr::replaceLaravel 版本引入的字符串替换方法v8.41.0
参考:https : //github.com/laravel/framework/releases/tag/v8.41.0