Hi am using laravel excel to import file from excel and getting the data but the column heading is getting changed and i need to keep is as same. For eg: column name is Mat_Type-1 then it get convert to mat_type_1.
Whereas i want to keep it as same to get some data out of the column.
Function in controller :
public function uploadexcel(Request $request){
// $this->validate($request, [
// 'importfile' => 'required|mimes:xls,xlsx'
// ]);
echo $path = $request->file('importfile');
$array = Excel::toArray(new ProductsImport, $path);
print_r($array);
}
Excel\Imports class:
namespace App\Imports;
use App\Models\Admin\CarVariant;
use App\Models\Admin\Product;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\Rule;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithBatchInserts;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithValidation;
class ProductsImport implements ToModel,WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
// dd($row);
}
}
Any help is deeply appreciated. Tried multiple option but not working.