I am trying to import excel file which is working fine. But when I try to add custom additional field values during import then those additional value is not getting import.
public function __construct($from, $to)
{
$this->from = $from;
$this->to = $to;
}
/****** Import Function *******/
public function model(array $row)
{
return new pgimport([
'field_one' => $row[0],
'field_two' => $row[1],
'field_three' => $row[2],
'field_four' => $row[3],
'field_five' => $row[4],
'field_six' => $row[5],
'field_seven' => $row[6],
'field_eight' => $row[7],
'additional_field_one' => $this->from, //Additional Value
'additional_field_two' => $this->to, //Additional Value
]);
}
In above code, I tried to echo both addition value ($this->from and $this->to) like this
public function model(array $row)
{
echo $this->from.' and '.$this->to; //ECHOING Values
die; //DIE TO STOP CODE
return new pgimport([
'field_one' => $row[0],
'field_two' => $row[1],
'field_three' => $row[2],
'field_four' => $row[3],
'field_five' => $row[4],
'field_six' => $row[5],
'field_seven' => $row[6],
'field_eight' => $row[7],
'additional_field_one' => $this->from, //Additional Value
'additional_field_two' => $this->to, //Additional Value
]);
}
In echo function, values of both variables are getting printed. So values are coming in variables but not submitting to database. Any idea please, why is this not working?
CodePudding user response:
Please check your model class file first. you should add 'additional_field_one' and 'additional_field_two' inside fillables. please check it firstly