-1

I have name, email and image input fields in a view file. I use jquery cloning in the view file. How to store the image, name and email values in the database by using laravel 5.8 creating a method?

This is my code:

public function addMorePost(Request $request) {
    $request->validate([
       'addmore.*.name' => 'required',
       'addmore.*.qty' => 'required',
       'addmore.*.price' => 'required',
       'addmore.*.image' => 'required',
    ]);

    foreach ($request->addmore as $key => $value) {
        ProductStock::create($value);
    }

    return back()->with('success', 'Record Created Successfully.');
}
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263

1 Answers1

0

You don't have to use the foreach container to loop through the request variables . Just get all the input variables by using,

$data = $request->all();

And then store into db by using $data variable .

ProductStock::create($data);
farooq
  • 1,603
  • 2
  • 17
  • 33