I am importing Excel Sheet using Excel::import Maatwebsite / Laravel Excel 3.1.
Controller
$sheet = Excel::toArray(new UsersImport(), $request->file('stock_file'),
null,\Maatwebsite\Excel\Excel::XLSX);
UserImport.php
use App\Models\User;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;
use Maatwebsite\Excel\Cell;
use Maatwebsite\Excel\Row;
use Maatwebsite\Excel\Concerns\OnEachRow;
class UsersImport implements ToModel, WithCalculatedFormulas, SkipsEmptyRows
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new User([
//
]);
}
public function sheets(): array
{
return ['0'];
}
public function collection(Collection $rows)
{
$sheet_data = $rows->toArray();
}
}
Result
Array
(
[0] => Array
(
[0] => Array
(
[0] => 1
[1] => Image
[2] => View
[3] => 7.84
[4] => 7.87
)
Expected
Array
(
[0] => Array
(
[0] => Array
(
[0] => 1
[1] => https://google.com
[2] => https://laravel.com
[3] => 7.84
[4] => 7.87
)