You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 11使用OpenAdmin创建控制器报错:isDoctrineAvailable方法不存在

解决Laravel 11 + OpenAdmin控制器生成时的isDoctrineAvailable错误

问题根源

Laravel 11 移除了Illuminate\Database\MySqlConnection类里的isDoctrineAvailable方法,但OpenAdmin的ResourceGenerator类仍在调用该方法,直接触发BadMethodCallException错误。

可行解决方案

方案1:安装兼容的doctrine/dbal版本

  1. 安装适配Laravel 11的doctrine/dbal版本(推荐^3.8):
composer require doctrine/dbal:^3.8
  1. 更新依赖并重新生成锁文件:
composer update
  1. 再次尝试生成控制器:
php artisan admin:controller \App\Models\User

方案2:直接修改OpenAdmin源码(临时应急)

找到OpenAdmin包中的ResourceGenerator.php文件(路径一般为vendor/open-admin-org/open-admin/src/Generators/ResourceGenerator.php),找到调用isDoctrineAvailable的代码块,把:

if ($this->connection->isDoctrineAvailable()) {

替换为:

if (class_exists(\Doctrine\DBAL\Connection::class)) {

保存后重新执行控制器生成命令即可。

方案3:用Composer补丁长期修复(推荐)

  1. 安装Composer补丁工具:
composer require cweagans/composer-patches --dev
  1. 在项目根目录创建patches文件夹,新建open-admin-fix-doctrine-check.patch文件,内容如下(注意替换实际行号和哈希值,可通过git diff获取):
diff --git a/src/Generators/ResourceGenerator.php b/src/Generators/ResourceGenerator.php
index abc123..def456 100644
--- a/src/Generators/ResourceGenerator.php
+++ b/src/Generators/ResourceGenerator.php
@@ -123,7 +123,7 @@ class ResourceGenerator extends Generator
             $schema = $this->connection->getDoctrineSchemaManager();
             $columns = $schema->listTableColumns($table);
 
-            if ($this->connection->isDoctrineAvailable()) {
+            if (class_exists(\Doctrine\DBAL\Connection::class)) {
                 foreach ($columns as $column) {
                     $columnName = $column->getName();
                     if (!in_array($columnName, $this->ignoreColumns)) {
  1. 在composer.json的extra字段中添加补丁配置:
"extra": {
    "patches": {
        "open-admin-org/open-admin": {
            "Fix Laravel 11 compatibility for isDoctrineAvailable": "patches/open-admin-fix-doctrine-check.patch"
        }
    }
}
  1. 执行composer install应用补丁,之后即可正常生成控制器。

内容的提问来源于stack exchange,提问作者Amna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 07:43:17