You are defining that you are getting an array here
model(array $row)
And then try to change it to an array here
$row->toArray()
You cannot change an array to an array
when i import csv file then not import duplicate email so i want some validation in import file but error
here is my code
<?php
namespace App\Imports;
use App\Library;
use Maatwebsite\Excel\Concerns\ToModel;
use Illuminate\Support\Facades\Validator;
class libraryImport implements ToModel
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
Validator::make($row->toArray(), [
'*.2' => 'required|email|unique:libraries,mail',
])->validate();
return new Library([
'id' => $row[0],
'name' => $row[1],
'mail' => $row[2],
'owner' => $row[3],
'contact_no' => $row[4],
'address' => $row[5],
'status' => $row[6],
// 'password' => \Hash::make('123456'),
]);
}
}
The error is pretty straight forward isn't it?
public function model(array $row)
You are passing array, and you try toArray() on it..
Use just this maybe:
Validator::make($row, [
'*.2' => 'required|email|unique:libraries,mail',
])->validate();
Please or to participate in this conversation.