首页 > 解决方案 > 我在 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();

标签: phplaravel-5

解决方案


您需要在查询中添加 table 方法,然后设置。

DB::connection('mysql / <or whatever mane you called it>')->table('crop_growth')-> rest of your query.

如果您仍然有错误,您可以在表字段中设置数据库。

table('<database>.crop_growth')

虽然我会先设置一个测试选择,然后是左连接,然后是实际选择,但这没关系。

祝你好运


推荐阅读