erhsaikhasif's avatar

How to Insert records in tables in Lumen when The POST variables name and table Column names are different?

Suppose I have 2 columns in My Table "fname" and "lname" and I am sending POSt request as { "firstname" : "BOB" , "lastname" : "Kylene"} , I gopt the data in $request variable in called function of controller. How could i store this values in table as column name are different. How Can I copy this request data in Other Object ,SO I can insert it in table.

0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122
$thing = Thing::create(['fname' => $request->firstname, 'lname' => $request->lastname]);

but honestly, I would just fix the form or the database so that you are using the same field names

2 likes
erhsaikhasif's avatar

Hello Snapey, You have given the example above to insert records is work for me. Thank you, THANK YOU So very much. I appreciate your reply. Thanks Again.

Please or to participate in this conversation.