How to insert array fields data in Laravel5

Method 1 :

$name =  $request->title;
    $description =  $request->email;

    if(count($name) > count($description))
        $count = count($description);
    else $count = count($name);


for($i = 0; $i < $count; $i++){
    $objModel = new ModelName();
    $objModel->name = $name[$i];
    $objModel->description = $description[$i];
    $objModel->save();
} 

Method 2 :

$name =  $request->title;
    $description =  $request->email;

    if(count($name) > count($description))
        $count = count($description);
    else $count = count($name);

    for($i = 0; $i < $count; $i++){
        $data = array(
            'name' => $name[$i],
            'description' => $description[$i]
        );

        $insertData[] = $data;
    }
 

Leave a Reply

Your email address will not be published. Required fields are marked *