vendredi 22 janvier 2016

Column not found: 1054 Unknown column - Laravel 5.1 Join

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. The only way I can get rid of this error is to remove my join statements. I'm stumped.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire