Where can I find this onlySheets
Method ?
I wanna import data from Excel file that contains sheet called "Clients".
I've created a ClientsImport.php
file :
<?php
namespace App\Imports;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class ClientsImport implements WithMultipleSheets
{
// MULTIPLE SHEETS
public function sheets(): array
{
return [
'clients' => new ClientsSheetImport(),
];
}
// END MULTIPLE SHEETS
}
and Then created ClientSheetImport.php
file to get rows and validate data from given Excel file :
<?php
namespace App\Imports;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithValidation;
// use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithMappedCells;
use App\Client;
class ClientsSheetImport implements ToModel, WithValidation, WithMappedCells
{
/**
* @param array $row
*
* @return Client|null
*/
public function model(array $row)
{
return new Client([
'nrc_entrp' => $row['nrc_entrp'],
'raisoci' => $row['raisoci'],
]);
}
public function rules(): array {
return [
'nrc_entrp'=> 'required|unique:clients|max:20',
'raisoci'=> 'required|unique:clients|max:100',
];
}
public function mapping(): array
{
return [
'nrc_entrp' => 'B1',
'raisoci' => 'B2',
];
} // mapping
}
and in ImportClientController.php
I wanna import one Sheet from Excel file ("Clients" sheet") with this Given Code :
$import_client = new ClientsImport();
$import_client->onlySheets('clients');
Excel::import($import_client, $file_url);
But I got this error :
Call to undefined method App\Imports\ClientsImport::onlySheets()
Where can I find this onlySheets
Method ?
Thanks