Replies: 1 comment 2 replies
-
WithUpserts is only supported for Laravel 8 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Error info:
BadMethodCallException: Call to undefined method App\Models\ApSales::upsert() in file D:\wwwroot\proapply\proapply7\proapply\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php on line 50
#0 D:\wwwroot\proapply\proapply7\proapply\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php(36): Illuminate\Database\Eloquent\Model::throwBadMethodCallException('upsert')
#1 D:\wwwroot\proapply\proapply7\proapply\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1736): Illuminate\Database\Eloquent\Model->forwardCallTo(Object(Illuminate\Database\Eloquent\Builder), 'upsert', Array)
#2 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Imports\ModelManager.php(149): Illuminate\Database\Eloquent\Model->__call('upsert', Array)
#3 D:\wwwroot\proapply\proapply7\proapply\vendor\laravel\framework\src\Illuminate\Support\Traits\EnumeratesValues.php(202): Maatwebsite\Excel\Imports\ModelManager->Maatwebsite\Excel\Imports{closure}(Object(App\Models\ApSales), 0)
#4 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Imports\ModelManager.php(161): Illuminate\Support\Collection->each(Object(Closure))
#5 D:\wwwroot\proapply\proapply7\proapply\vendor\laravel\framework\src\Illuminate\Support\Traits\EnumeratesValues.php(202): Maatwebsite\Excel\Imports\ModelManager->Maatwebsite\Excel\Imports{closure}(Array, 2)
#6 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Imports\ModelManager.php(162): Illuminate\Support\Collection->each(Object(Closure))
#7 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Imports\ModelManager.php(73): Maatwebsite\Excel\Imports\ModelManager->singleFlush(Object(App\Imports\SaleImport))
#8 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Imports\ModelImporter.php(81): Maatwebsite\Excel\Imports\ModelManager->flush(Object(App\Imports\SaleImport), false)
#9 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Sheet.php(261): Maatwebsite\Excel\Imports\ModelImporter->import(Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet), Object(App\Imports\SaleImport), 1)
#10 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Reader.php(115): Maatwebsite\Excel\Sheet->import(Object(App\Imports\SaleImport), 1)
#11 D:\wwwroot\proapply\proapply7\proapply\vendor\laravel\framework\src\Illuminate\Database\Concerns\ManagesTransactions.php(28): Maatwebsite\Excel\Reader->Maatwebsite\Excel{closure}(Object(Illuminate\Database\MySqlConnection))
#12 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Transactions\DbTransactionHandler.php(30): Illuminate\Database\Connection->transaction(Object(Closure))
#13 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Reader.php(129): Maatwebsite\Excel\Transactions\DbTransactionHandler->__invoke(Object(Closure))
#14 D:\wwwroot\proapply\proapply7\proapply\vendor\maatwebsite\excel\src\Excel.php(146): Maatwebsite\Excel\Reader->read(Object(App\Imports\SaleImport), 'tempfile/excel/...', 'Xlsx', NULL)
#15 D:\wwwroot\proapply\proapply7\proapply\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(261): Maatwebsite\Excel\Excel->import(Object(App\Imports\SaleImport), 'tempfile/excel/...')
#16 D:\wwwroot\proapply\proapply7\proapply\app\Http\Controllers\Upload\UploadController.php(90): Illuminate\Support\Facades\Facade::__callStatic('import', Array)
Environment:
Laravel: 7.X;
PHP: ^7.3;
Import Code start:
namespace App\Imports;
use App\Models\ApSales;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithUpserts;
class SaleImport implements ToModel, WithUpserts {
public function model(array $row) {
if ($row[0]==="gid") {
return null;
}
return new ApSales([
'gid' => $row[0],
'username' => $row[1],
]);
}
public function uniqueBy() {
return 'gid';
}
}
ApSales Code start:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ApSales extends Model {
protected $table = 'ap_sales';
public $timestamps = false;
}
Controller Code:
Excel::import(new SaleImport($request), $filePath);
### Help me!!!!
Beta Was this translation helpful? Give feedback.
All reactions