php - 我在 laravel 查询语言中遇到错误
问题描述
Illuminate\Database\Connection::table() 缺少参数 1
我在表函数中传递参数。我正在使用的数据库的每个功能上都收到此错误。
当我创建模型的对象然后使用函数时它工作正常table()
。
这是我正在使用的代码。
return DB::table('crop_growth')
->leftJoin('farmer_details', 'crop_growth.farmer_id', '=', 'farmer_details.id')
->select('crop_growth.id', 'crop_growth.remind_after', 'crop_growth.reason', 'crop_growth.is_read', 'farmer_details.name', 'farmer_details.phone')
->where('crop_growth.emp_id', $empId)
->where('crop_growth.remind_after', '!=', null)
->orderBy('crop_growth.is_read', 'ASC')
->orderBy('crop_growth.remind_after', 'ASC')
->get();
解决方案
您需要在查询中添加 table 方法,然后设置。
DB::connection('mysql / <or whatever mane you called it>')->table('crop_growth')-> rest of your query.
如果您仍然有错误,您可以在表字段中设置数据库。
table('<database>.crop_growth')
虽然我会先设置一个测试选择,然后是左连接,然后是实际选择,但这没关系。
祝你好运
推荐阅读
- spring-data-mongodb - Spring MongoTemplate 不是正在进行的事务的一部分
- php - 无法通过 PHP 但使用 Postman 接收标头信息
- ansible - 如何在 jinja2 中转义双花括号?
- java - 当我尝试将我的应用程序连接到 webServices 时失败
- java - 如何在不清除窗口的情况下在 Swing 中重新绘制?
- google-apps-script - How to write Google Analytics API data to a new row, rather than a new sheet
- c++ - 为什么将临时对象作为参数传递需要 std::move?
- git - 如何关闭 git 输出中的帮助提示?
- c++ - 将流转换为布尔 - 如何在 getline() 中完成
- javascript - console.log 消息被截断