diff --git a/src/Eloquent/Connection.php b/src/Eloquent/Connection.php index 5fd26b9..a9f6a9f 100644 --- a/src/Eloquent/Connection.php +++ b/src/Eloquent/Connection.php @@ -134,6 +134,13 @@ public function zohoUpsert(string $toTable, array $data, array|string $key): int $key = [$key]; } + foreach ($data as $rowIndex => $row) { + foreach ($row as $field => $value) { + $row[$field] = $value instanceof \Stringable ? (string) $value : $value; + } + $data[$rowIndex] = $row; + } + return $this->getClient()->importUpsert($toTable, $data, $key); } diff --git a/src/Eloquent/ZohoModel.php b/src/Eloquent/ZohoModel.php index 7efecb4..718c7f1 100644 --- a/src/Eloquent/ZohoModel.php +++ b/src/Eloquent/ZohoModel.php @@ -8,7 +8,6 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Date; use Portable\EloquentZoho\Casts\ZohoInteger; -use Portable\EloquentZoho\Eloquent\Query\Builder as QueryBuilder; abstract class ZohoModel extends Model { @@ -26,24 +25,6 @@ public function __construct(array $attributes = []) $this->casts = array_merge($this->casts, ['id' => ZohoInteger::class]); } - /** - * {@inheritdoc} - */ - public function newEloquentBuilder($query) - { - return new Builder($query); - } - - /** - * {@inheritdoc} - */ - protected function newBaseQueryBuilder() - { - $connection = $this->getConnection(); - - return new QueryBuilder($connection, $connection->getQueryGrammar(), $connection->getPostProcessor()); - } - /** * Get the current connection name for the model. * diff --git a/src/Providers/ZohoServiceProvider.php b/src/Providers/ZohoServiceProvider.php index f32a840..42a2e81 100644 --- a/src/Providers/ZohoServiceProvider.php +++ b/src/Providers/ZohoServiceProvider.php @@ -3,7 +3,8 @@ namespace Portable\EloquentZoho\Providers; use Illuminate\Support\ServiceProvider; -use Portable\EloquentZoho\Eloquent\Connection; +use Portable\EloquentZoho\Eloquent\Connection as ZohoConnection; +use Illuminate\Database\Connection; class ZohoServiceProvider extends ServiceProvider { @@ -17,12 +18,8 @@ public function register(): void 'eloquent-zoho' ); // Add database driver. - $this->app->resolving('db', function ($db) { - $db->extend('zoho', function ($config, $name) { - $config['name'] = $name; - - return new Connection($config); - }); + Connection::resolverFor('zoho', function ($connection, $database, $prefix, $config) { + return new ZohoConnection($config); }); }