Klav
Klav

Reputation: 405

Array to string conversion Exception Laravel 4.2

Slowly moving a project into Laravel. Using a loop I'm capturing all the form input arrays.

The exception is thrown on:

$data[] = "['job_id' => '$jobID', 'first_name' => '$name', 'dob' => '$dob']";

Larger context:

$jobID = 2;
$data = array();
foreach(Input::get('name') as $row=>$name){

    $name = Input::get('name');
    $dob = Input::get('dob'.$row);

    $data[] = "['job_id' => '$jobID', 'first_name' => '$name', 'dob' => '$dob']";

}

$data_insert = implode(',', $data);

if(!empty($name)) {
    DB::table('job_data')->insert([
        $data_insert
    ]);

}

Upvotes: 0

Views: 125

Answers (1)

Saad Imran.
Saad Imran.

Reputation: 4530

I'm guessing $name = Input::get('name'); returns an array. Try removing the line completely, it's unecessary because $name is already defined.

Upvotes: 2

Related Questions