nafeeur10
1 week ago

How to store array in DB: Array to String Conversion Error!

Posted 1 week ago by nafeeur10

I want to store an array in my Database. But what will be the right approach?

I am trying like this:

var settings = {
	serial: 1,
	customer_payment_option: [
		cash=> this.cash,
		online=> this.online,
		bank_transfer=> this.bankTransfer
	]
}

Controller:

function save(Request $request) 
    {
        $obj= new Setting();
        $obj->setting_option_id = $request->settings['serial'];
        $obj->value = $request->settings['customer_payment_option'];

        $obj->save();

        return response()->json([
            'message' => 'Settings Added Successfully!'
        ]);
    }

Please sign in or create an account to participate in this conversation.