LaravelDb 文件不存在,导致 数据库链接异常

abxk

问题描述

Error: Call to a member function connection() on null in E:\code\my-app\app\webman\vendor\illuminate\database\Eloquent\Model.php:1851

发现 config/bootstrap.php 没有 support\bootstrap\LaravelDb::class;
截图

排查发现 github 仓库没有这个文件;
截图

重现问题的步骤

根据文档一步步全新安装框架及数据库ORM

操作系统环境及workerman/webman等具体版本

win10
php:PHP 8.2.9 (cli) (built: Aug 1 2023 12:41:16) (NTS Visual C++ 2019 x64)

{
  "name": "workerman/webman",
  "type": "project",
  "keywords": [
    "high performance",
    "http service"
  ],
  "homepage": "https://www.workerman.net",
  "license": "MIT",
  "description": "High performance HTTP Service Framework.",
  "authors": [
    {
      "name": "walkor",
      "email": "walkor@workerman.net",
      "homepage": "https://www.workerman.net",
      "role": "Developer"
    }
  ],
  "support": {
    "email": "walkor@workerman.net",
    "issues": "https://github.com/walkor/webman/issues",
    "forum": "https://wenda.workerman.net/",
    "wiki": "https://workerman.net/doc/webman",
    "source": "https://github.com/walkor/webman"
  },
  "require": {
    "php": ">=8.1",
    "workerman/webman-framework": "~2.1",
    "monolog/monolog": "^2.0",
    "webman/redis": "^2.1",
    "webman/cache": "^2.1",
    "webman/redis-queue": "^1.3",
    "vlucas/phpdotenv": "^5.6",
    "workerman/crontab": "^1.0",
    "webman/console": "^2.1",
    "firebase/php-jwt": "^6.11",
    "tinywan/jwt": "^1.11",
    "php-di/php-di": "^7.0",
    "webman-tech/laravel-validation": "^11.0",
    "ramsey/uuid": "^4.9",
    "ext-pdo": "*",
    "webman/event": "^1.0",
    "webman/database": "^2.1",
    "illuminate/pagination": "^11.45",
    "illuminate/events": "^11.45",
    "symfony/var-dumper": "^7.3",
    "workerman/workerman": "~5.1"
  },
  "suggest": {
    "ext-event": "For better performance. "
  },
  "autoload": {
    "psr-4": {
      "": "./",
      "app\\": "./app",
      "App\\": "./app",
      "app\\View\\Components\\": "./app/view/components"
    }
  },
  "scripts": {
    "post-package-install": [
      "support\\Plugin::install"
    ],
    "post-package-update": [
      "support\\Plugin::install"
    ],
    "pre-package-uninstall": [
      "support\\Plugin::uninstall"
    ]
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "require-dev": {
    "phpunit/phpunit": "^11.5",
    "mockery/mockery": "^1.6"
  }
}
64 1 1
1个回答

abxk

手动新建文件, 并在config/bootstrap.php 引入即可解决。
walkor/webman-framework v2.0.0 存在该文件,之后版本,LaravelDb 被移除。
截图

<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

namespace support;

use Webman\Bootstrap;
use Webman\Database\Initializer;
use Workerman\Worker;
/**
 * Class Laravel
 * @package support\Bootstrap
 */
class LaravelDb implements Bootstrap
{
    /**
     * @param Worker|null $worker
     *
     * @return void
     */
    public static function start(?Worker $worker)
    {
        if (!class_exists(Initializer::class)) {
            return;
        }
        Initializer::init(config('database', []));
    }
}
  • 暂无评论
🔝