I'm exporting an excel file to a database using Laravel excel
class StudentsImport implements ToModel
{
public function model(array $row)
{
return new Students([
'student_name' => $row[0],
'student_email' => $row[1],
}
}
and it works fine, I however also want to pass a universal variable that is not in the excel file. In this case, the school_id is available in the controller but I can't figure out how to pass it to the imports class.
public function model(array $row)
{
return new Students([
'student_name' => $row[0],
'student_email' => $row[1],
'school_id' => $school_id,
}
Help will be appreciated. Thanks.