gpt4 book ai didi

php - 在 Ratchet 的 MessageComponentInterface 中访问 Eloquent ORM

转载 作者:行者123 更新时间:2023-12-04 16:14:12 26 4
gpt4 key购买 nike

标题令人困惑。基本上,我无法在不属于框架的类中访问 Laravel 的实用程序。
错误是:Call to a member function connection() on null in C:\xampp\htdocs\blazocket\vendor\laravel\framework\src\Illuminate\Databas e\Eloquent\Model.php:1571我有一个基于 Ratchet 库的 Websocket 服务器,它具有以下结构:

namespace App\Http\Websockets;
$server = new \Ratchet\App('localhost', 8080);
$server->route('/api/socket', new WebSocketHandler, array('*'));
来自 WebSocketHandler 的片段:
namespace App\Http\Websockets;
use App\Models\Website;

class WebSocketHandler implements MessageComponentInterface {



protected $apis;
protected $clients;

public function __construct() {
$this->refreshDatabase();
$this->clients = new \SplObjectStorage;
}

private function refreshDatabase(){
$this->apis = Website::all();
}

}
我试过这样做:
$app = require dirname( __FILE__ ) . '/../../../bootstrap/app.php';
$app->boot();
但这不是解决方案(我从不同的 SO 问题中尝试过)。另外,我读过 this ,但我不确定我可以实现“引导”事情的方式。
我知道错误的发生是因为类 (WebSocketHandler) 和 Laravel 框架之间没有连接。我已经尝试了每一个答案,并检查了文档,我无法自己找到一种方法来连接这门课。
非常感谢您的帮助。

最佳答案

您错过了声明命名空间。如您所见 here
有一个命名空间声明。

关于php - 在 Ratchet 的 MessageComponentInterface 中访问 Eloquent ORM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68488208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com