-2

How to insert an array to database in Laravel 5.6 Array in controller

public function insert(Request $request )
{
    $idsArry = $request->input('id'); 

    DB::table('work_user')->insert(array(['WorkID' => $idsArry]));

    return redirect ("/works_assign")->with("Success", "Deleted Successfully") ;
}
9
  • json_encode(['WorkID'=>$idsArry]) your array and save it in a varchar or text Commented Jan 14, 2020 at 9:23
  • you would like to insert multiple row for each id in $idsArry there; or you can just json_encode() the array and json_decode() to get data back. Commented Jan 14, 2020 at 9:25
  • plz post your work_user structure. Commented Jan 14, 2020 at 9:30
  • And plz post $idsArry too? Commented Jan 14, 2020 at 9:35
  • Id int(11) WorkID int(11) CusName varchar(100) $idsArry=[1,2,3]; @TsaiKoga Commented Jan 14, 2020 at 9:39

1 Answer 1

0
  $array = [
    'one' => $one,
    'two' => $two,
    'nine' => $nine,
    'ten' => $ten,
   ];

  YourModel::create($array)
Sign up to request clarification or add additional context in comments.

1 Comment

@ArunVinoth this is easy, just put array in create() and it will work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.