Laravel 调试模型连接以检查 env 函数是否正确解析凭据
Laravel debug the Model connection to check if the env function is parsing the credentials properly
正在 Laravel 5.8.x 版本中处理多数据库、多连接项目。
我创建了一个模型,用于使用特定连接从特定数据库中获取数据。
我已将模型文件中的连接变量定义为:
protected $connection = '[ConnName]';
并且我在 config/database.php 中将上述连接设置为:
'connections' => [
'[ConnName]' => [
'username' => env('username'),
....
],
....
]
仍然当我尝试将模型的数据加载到控制器的索引操作中时:
$modelData = Model::orderBy('created_at', 'DESC');
exit(print_r(compact($modelData)));
return view('entity.index', compact('modelData'));
它打印 null/no 条记录,即使数据库中有数据通过所述连接与模型链接。
任何人都可以建议交叉检查连接凭据是否通过 env 方法正确解析或如何在控制器中打印使用的连接?
确保模型有 ->get()
$modelData = Model::orderBy('created_at', 'DESC')->get();
dd($modelData);
正在 Laravel 5.8.x 版本中处理多数据库、多连接项目。
我创建了一个模型,用于使用特定连接从特定数据库中获取数据。
我已将模型文件中的连接变量定义为:
protected $connection = '[ConnName]';
并且我在 config/database.php 中将上述连接设置为:
'connections' => [
'[ConnName]' => [
'username' => env('username'),
....
],
....
]
仍然当我尝试将模型的数据加载到控制器的索引操作中时:
$modelData = Model::orderBy('created_at', 'DESC');
exit(print_r(compact($modelData)));
return view('entity.index', compact('modelData'));
它打印 null/no 条记录,即使数据库中有数据通过所述连接与模型链接。
任何人都可以建议交叉检查连接凭据是否通过 env 方法正确解析或如何在控制器中打印使用的连接?
确保模型有 ->get()
$modelData = Model::orderBy('created_at', 'DESC')->get();
dd($modelData);