我需要匹配两个表并将其插入到支出表中,所以这是我的代码......
public function store(Request $request)
{
//Approved Request
$approvedRequest= DB::table('request')
->where('users_MemId',Auth::user()->MemId)
->where('requestStatus','Approved')
->join('requestdetails','request.requestId','=','requestdetails.request_requestId')
->join('itemattribute','requestdetails.RequestDetailsId','=','itemattribute.RequestDetailsId')
->join('exudeinventory', 'itemattribute.AttrName', '=', 'exudeinventory.ItemName')
->select('itemattribute.AttrName', 'exudeinventory.InventoryId', 'request.requestId')
->get();
// dd($approvedRequest);
存储功能。
我已经尝试过匹配这些表格了,我无法弄清楚如何在另一个表格中插入这些值,或者我是否正确行事。
我一直在寻找解决方案,但我仍然无法理解,希望有人能帮助我并向我解释,我是laravel T的新手,T
答案 0 :(得分:0)
也许你可以这样做:
public function store(Request $request)
{
//Approved Request
$approvedRequest= DB::table('request')
->where('users_MemId',Auth::user()->MemId)
->where('requestStatus','Approved')
->join('requestdetails','request.requestId','=','requestdetails.request_requestId')
->join('itemattribute','requestdetails.RequestDetailsId','=','itemattribute.RequestDetailsId')
->join('exudeinventory', 'itemattribute.AttrName', '=', 'exudeinventory.ItemName')
->select('itemattribute.AttrName', 'exudeinventory.InventoryId', 'request.requestId')
->get()
->each (function ($request, $key) {
$dis = new Disbursment;
$dis->DisbursmentId = rand(1, 999999);
$dis->ItemImage = 'default.jpg';
$dis->ItemTypeId = $request->AttrName;
$dis->exudeinventory_InventoryId = $request->InventoryId;
$dis->request_requestId = $request->requestId;
$dis->save();
});
}