Laravel 11集成Mews Captcha报错:relation 'cache'不存在
Laravel 11 集成 Mews Captcha 问题解决方案
一、解决「cache表不存在」的数据库错误
错误提示SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "cache" does not exist,是因为当前Laravel缓存驱动配置为database,但缺少对应的缓存表。有两种解决方式:
方式1:创建database缓存表
执行以下命令生成并运行缓存表迁移:
php artisan cache:table php artisan migrate
方式2:切换缓存驱动
如果不需要用数据库缓存,直接修改.env文件,将缓存驱动改为文件或Redis:
CACHE_DRIVER=file
修改后执行配置缓存清除:
php artisan config:clear
二、Laravel 11 注册Mews Captcha服务提供者与别名
Laravel 11移除了config/app.php中的providers和aliases配置项,需通过以下方式注册:
注册服务提供者
打开bootstrap/providers.php,添加Captcha服务提供者到返回数组中:
return [ // 保留原有服务提供者 Mews\Captcha\CaptchaServiceProvider::class, ];
注册别名(可选)
如果需要使用Captcha门面别名,打开bootstrap/app.php,在应用配置链中添加->alias()方法:
return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) ->withMiddleware(function (Middleware $middleware) { // 中间件配置 }) ->withProviders() ->alias('Captcha', Mews\Captcha\Facades\Captcha::class) // 添加此行 ->create();
最后验证
执行以下命令清除缓存,然后重新访问验证码页面:
php artisan config:clear php artisan cache:clear
内容的提问来源于stack exchange,提问作者Ashish
相关产品推荐
相关产品推荐

