无需 Artisan 命令即可清除 Laravel 缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53545160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:10:59  来源:igfitidea点击:

Clear Laravel cache(s) without Artisan command

phplaravelcachinglaravel-5

提问by Matthew

I've moved my project but have run into an issue. I'm discovering that the old settings (which have been changed in my .envto reflect the changed host) are still being used by my project.

我已经移动了我的项目,但遇到了一个问题。我发现.env我的项目仍在使用旧设置(已更改以反映更改的主机)。

I can't access my project through a browser as it returns this error: SQLSTATE[HY000] [1045] Access denied for user 'appReop'@'localhost' (using password: YES) (SQL: select * from `settings` limit 1)

我无法通过浏览器访问我的项目,因为它返回此错误: SQLSTATE[HY000] [1045] Access denied for user 'appReop'@'localhost' (using password: YES) (SQL: select * from `settings` limit 1)

appReopwas the previous login username. And while I could just create a new user to reflect this, I also run into an issue about the old password being too weak for the current database configuration.

appReop是之前的登录用户名。虽然我可以创建一个新用户来反映这一点,但我也遇到了一个问题,即旧密码对于当前数据库配置来说太弱了。

When I go to run php artisan cache:clear, it returns the same above error. So I was curious if there was a way to manually clear the caches to fix my errors?

当我去运行 php artisan cache:clear 时,它返回与上述相同的错误。所以我很好奇是否有办法手动清除缓存来修复我的错误?

Update

更新

This shows the three errors that pop up after running any Artisan command:

这显示了运行任何 Artisan 命令后弹出的三个错误:

enter image description here

在此处输入图片说明

回答by Jimmy

Not sure you have solved this, my suggestion is remove the files inside below folder. So the database connection cache file will create again after removed. (Laravel 5)

不确定您是否已解决此问题,我的建议是删除以下文件夹中的文件。所以数据库连接缓存文件删除后会重新创建。(Laravel 5)

/<root>/bootstrap/cache/*

Hope it helps :)

希望能帮助到你 :)

回答by MD. Jubair Mizan

You can call an Artisan command outside the CLI.

您可以在 CLI 之外调用 Artisan 命令。

Route::get('/clear-cache', function() {
   $exitCode = Artisan::call('cache:clear');
   // return what you want
});

You can check the official doc here http://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli

您可以在此处查看官方文档http://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli

回答by Felippe Duarte

It's one time only? Just delete the folder storage/framework/cache/data

是不是只有一次?删除文件夹就好了storage/framework/cache/data

回答by Josh

Try running:

尝试运行:

php artisan down
php artisan config:clear

As this will place Laravel in maintenance mode and then clear only the config setting cache.

因为这会将 Laravel 置于维护模式,然后仅清除配置设置缓存。

@Filippe commented about this already.

@Filippe 已经对此发表了评论。

Update

更新

Just create a file called down like in the picture below then run php artisan config:clearand then if it works php artisan up.

只需创建一个如下图所示的文件,然后运行php artisan config:clear,然后运行php artisan up

enter image description here

在此处输入图片说明

回答by Manish J

rather batter if you could provide permission to your storage directory.

如果您可以为您的存储目录提供权限,那就更好了。

$ sudo chmod -R 777 ./storage

then remove cache and using php artisan cache:clear.I hope this will help you.

然后删除缓存并使用php artisan cache:clear。我希望这会帮助你。

回答by Andrey Mikhalev

If someone still has such problem, check out your password for database. It seems like .env file does not accept # sign, that's why I had the same error.

如果有人仍然有这样的问题,请检查您的数据库密码。似乎 .env 文件不接受 # 符号,这就是我遇到相同错误的原因。