在Laravel中加入3个表后,我试图查看特定表的日期。但它只显示一个表的信息。
下面是连接3个表的代码:
路由文件:
$invoices= DB::table('sales_accounts')
->join('invoices', 'sales_accounts.id', '=', 'invoices.sales_Accounts_id')
->join('subscribers', 'invoices.receiver_id', '=', 'subscribers.id')
->where('sales_accounts.sender_id', $fieldForceID)
->get();
return Response::json($invoices);
下面是在Blade模板中查看信息的脚本
刀片代码:
function(data) {
$.each(data, function(index, element) {
console.log(element);
infoShare.append("<pre> Date Of Invoice : "+element.created_at+" | Pos Address : "+element.subscriber_address+"| Total Amount: "+element.cost+" </pre>");
});
});
在这里,我想查看发票的创建日期,但它显示了subscriber from subscribers表的创建日期。但我想从发票表中查看发票的具体日期。
我该怎么做?当做
最佳答案
我做到了!!!
如果我像这样更改联接查询,它将显示表的特定值。
路由文件中的查询:
$invoices= DB::table('sales_accounts')
->join('invoices', 'sales_accounts.id', '=', 'invoices.sales_Accounts_id')
->join('subscribers', 'invoices.receiver_id', '=', 'subscribers.id')
->where('sales_accounts.sender_id', $fieldForceID)
->get(['invoices.created_at','invoices.debit','invoices.credit','invoices.cost','subscribers.subscribers_address']);
返回Response::json($invoices);
现在一切正常了!!!
使用SaleCount模型更新查询:
$fieldForceID=Input::get('option');
$invoices= SaleAccount::where('sales_accounts.sender_id', $fieldForceID)
->join('invoices', 'sales_accounts.id', '=', 'invoices.sales_Accounts_id')
->join('subscribers', 'invoices.receiver_id', '=', 'subscribers.id')
->get(['invoices.created_at','invoices.debit','invoices.credit','invoices.cost','subscribers.subscriber_address']);
return Response::json($invoices);