我试图在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 In 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>");
});
});
此处我想查看发票的创建日期,但它显示了订阅者表中订阅者的创建日期。但我想从发票表中查看发票的具体日期。
我怎么能这样做?此致
答案 0 :(得分: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(['invoices.created_at','invoices.debit','invoices.credit','invoices.cost','subscribers.subscribers_address']);
返回Response :: json($ invoices);
现在它工作正常!!!
使用SaleAccount模型更新查询:
$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);
答案 1 :(得分:0)
试试吧
在路线文件
中的发票查询中添加此项->addSelect(\DB::raw('invoices.created_At as invoce_created'))
在刀片文件
上获取发票crated_at日期element.invoce_created