Error: Call to a member function connection() on null in E:\code\my-app\app\webman\vendor\illuminate\database\Eloquent\Model.php:1851
發(fā)現(xiàn) config/bootstrap.php 沒有 support\bootstrap\LaravelDb::class;
排查發(fā)現(xiàn) github 倉庫沒有這個(gè)文件;
根據(jù)文檔一步步全新安裝框架及數(shù)據(jù)庫ORM
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": "http://m.wtbis.cn",
"license": "MIT",
"description": "High performance HTTP Service Framework.",
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://m.wtbis.cn",
"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"
}
}
手動(dòng)新建文件, 并在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://m.wtbis.cn/
* @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', []));
}
}