Home How to match two tables and insert it into another table in laravel 5.4?
Reply: 1

How to match two tables and insert it into another table in laravel 5.4?

Shinax Mahiro
1#
Shinax Mahiro Published in 2017-11-07 21:36:14Z

I need to match two tables and insert it into the disbursment table, so this is my code...

    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);

store function.

I've tried matching the tables and I can't figure out on how to insert the values in another table or if I am doing it right.

I've been looking for solutions but still I can't figure it out, Hope that someone would help me and explain it to me, I am new to laravel T,T

ako
2#
ako Reply to 2017-11-07 21:55:04Z

Maybe you can do this:

        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();
            });
        }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299044 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO