alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

Can't insert array with a variable in Laravel Controller anyone can answer

Can't insert array with a variable in Laravel Controller anyone can answer

I can't see the rest of the code to be sure but my guess is you're using a closure which removes $member_id form the scope of your loop. If that's the case, then the use keyword will allow you to access variables outside of the scope of the closure. For example -

 function () use ($member_id) { // pass $member_id into scope of closure
    foreach ($request->moreFields as $key => $value) {
        Permit::create([    
            'member_id' => $member_id,
            'license_type' => $request->license_type[$i],
            'license_number' => $request->license_number[$i],
            'registration_date' => $request->registration_date[$i],
            'expiration_date' => $request->expiration_date[$i],
        ]);
    }
};

90 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online