I'm using this libray to manage excel file on laravel project (https://docs.laravel-excel.com/3.1/getting-started/)
I would like to readonly excel file once I upload in from local and return as JSON.
My code in controller is
$excel = $request->file('excel');
$array = Excel::import(new ProductsImport, $excel);
where ProductsImport file is
<?php
namespace App\Imports;
use App\Models\Product;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\ToModel;
class ProductsImport implements ToModel
{
use Importable;
/**
* @param array $row
*
* @return Products|null
*/
public function model(array $row)
{
//return $row;
return new Product([
'name' => $row[0],
'email' => $row[1]
]);
}
}