drjltlm156790 2016-01-22 21:06
浏览 52
已采纳

未找到列:1054未知列 - Laravel 5.1加入

I have three tables. work_orders, customers, and aircraft. In the work_orders table there are two fields customer_id and aircraft_id. I'm trying to retrieve the customers and aircraft data through the use of join. I am getting an array of errors, but they all seem to be pointed in the same direction and that is that the table cannot be found.

Here is my WorkOrderController index:

public function index(WorkOrder $workorder)
{
$workorder_array = $workorder
    ->join('work_orders as work', 'work.aircraft_id', '=', 'aircraft.id')
    ->join('work_orders as workorder', 'workorder.customer_id', '=', 'customers.id')
    ->select('work_orders.opened_date', 'customers.mobile', 'aircraft.year')
    ->get();

return view('work-orders.index', compact('workorder_array'));
}

And with this I get the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'aircraft.id' in 'on clause' (SQL: select work_orders.opened_date from work_orders inner join work_orders as work on aircraft.id = work.aircraft_id inner join work_orders as workorder on workorder.customer_id = customers.id)

I've tried switching work.aircraft_id with aircraft.id, because the Laravel Docs show it in that order, but that doesn't make any difference either. The only way I can get rid of this error is to remove my join statements.

  • 写回答

1条回答 默认 最新

  • dongyulian5801 2016-01-24 19:32
    关注

    I had the wrong table in the join statement. Here's what I should have had:

    public function index(WorkOrder $workorder)
    {
        $workorder_array = $workorder
            ->join('aircraft', 'work_orders.aircraft_id', '=', 'aircraft.id')
            ->join('customers', 'work_orders.customer_id', '=', 'customers.id')
            ->select('*')
            ->get();
    
        return view('work-orders.index', compact('workorder_array'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程