How to store multiple Array values in one column in PHP

In this tutorial, I’m going to learn how to store multiple data in one field. so follow this tutorial in this tutorial we have mentioned it in a very easy way.

Step 1: In Blade Page get data in a foreach().

@foreach($user_slug_summary as $index => $item)
                    <input type="hidden" value="{{ $item->slug }}" name="influencer_name[]" id="influencer_name{{ $index }}" />
                    <input type="hidden" value="{{ $item->influencer_email }}" name="influencer_email[]" id="influencer_email{{ $index }}" />
                    @endforeach

Step 2: In the Controller,

Store function:-

Log::info("success m kya aa rha h" . json_encode($request->influencer_email));

$payment = new paypal();
$influencerEmails = $request->session()->get('influencer_email', []);
                $influencerNames = $request->session()->get('influencer_name', []);
                if (!empty($influencerEmails)) {

                    $influencers = [];
                    for ($i = 0; $i < count($influencerEmails); $i++) {
                        $influencers[] = [
                            'influencer_email' => $influencerEmails[$i],
                            // 'influencer_name' => $influencerNames[$i]
                        ];
                    }
                    $payment->influencer_email = json_encode($influencers);
                }
                if (!empty($influencerNames) ) {

                    $influencersname = [];
                    for ($i = 0; $i < count($influencerNames); $i++) {
                        $influencersname[] = [
                            // 'influencer_email' => $influencerEmails[$i],
                            'influencer_name' => $influencerNames[$i]
                        ];
                    }
                    $payment->influencer_name = json_encode($influencersname);
                }

                $payment->save();

Hopefully, It will help You !!!!!!

Related Posts

Professional Skill Alignment Around MLOps Foundation Certification in Modern Workplaces

Introduction The MLOps Foundation Certification has emerged as a critical benchmark for professionals looking to bridge the gap between data science and production engineering. This guide is…

Read More

Certified AIOps Manager: Strategic Framework for Intelligent IT Operations

Introduction The Certified AIOps Manager program is a specialized training designed to help professionals lead the next wave of IT operations. This guide is for engineers and…

Read More

Advanced AIOps Architect Certification Roadmap for DevOps Engineers

Introduction The Certified AIOps Architect is a comprehensive professional program designed for engineers and architects who want to master the intersection of Artificial Intelligence and IT Operations….

Read More

Advanced Certified AIOps Professional Guide for Mastering AI Driven Operations Skills

Introduction Artificial Intelligence for IT Operations is the future of managing complex systems and large scale digital environments. The Certified AIOps Professional program is designed for those…

Read More

Certified AIOps Engineer Training to Boost Automation Monitoring and Career Growth

The Certified AIOps Engineer is a specialized professional program designed to integrate artificial intelligence into modern IT operations. As systems scale and generate massive amounts of telemetry…

Read More

Advanced Guide to AIOps Foundation Certification for Scalable IT Infrastructure

In an era where infrastructure and applications generate massive amounts of telemetry data, manual intervention is no longer a sustainable strategy for maintaining system uptime. The AIOps…

Read More