Because you can access the request object any where in your project. This may work:
class CsvImport implements ToModel
{
public function model(array $row)
{
return new Computer([
'first_name' => $row[0],
'last_name' => $row[1],
'asset_tag' => $row[2],
'pc_name' => request('pc_name');
]);
}
}
Or, you can pass the pc name to the CsvImport instance.
class CsvImport implements ToModel
{
protected $pcName;
public function __construct(string $pcName)
{
$this->pcName = pcName;
}
public function model(array $row)
{
return new Computer([
'first_name' => $row[0],
'last_name' => $row[1],
'asset_tag' => $row[2],
'pc_name' => $this->pcName;
]);
}
}
Then in your controller:
public function csv_import(Request $request) {
Excel::import(
new CsvImport($request->input('pc_name')),
$request->file('file')
);
return back();
}