How to get excel to array in maatwebsite
I and @narayan tried hard to make requested excel file into array. Now I am able to get array properly with below code
$rows = Excel::toArray(new SalesOrderImport, $request->file('sampledata'));
In my SalesOrderExport class I have default function only, which is required as abstract method.
namespace App\Exports;
use App\SalesOrder;
use Maatwebsite\Excel\Concerns\FromCollection;
class SalesOrderExport implements FromCollection
{
public function collection()
{
return SalesOrder::all();
}
}
My Controller code
public function importTest(Request $request)
{
$rows = Excel::toArray(new SalesOrderImport, $request->file('sampledata'));
return response()->json(["rows"=>$rows]);
}
And in HTML
<input class="" type="file" name="sampledata" id="sampledata">
I already created this export by
php artisan make:import SalesOrder
Attaching related images