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;
    }
 
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments