From 50dfea6232f5bd63387ea8934fb188b4053a0aeb Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Thu, 18 Apr 2024 19:21:32 +0330 Subject: [PATCH 1/8] feat: add getQuery method --- src/Contracts/DataSource.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Contracts/DataSource.php b/src/Contracts/DataSource.php index 1a9a71b3..4c005530 100644 --- a/src/Contracts/DataSource.php +++ b/src/Contracts/DataSource.php @@ -2,6 +2,8 @@ namespace LaraZeus\Bolt\Contracts; +use Illuminate\Database\Eloquent\Builder; + interface DataSource { public function title(): string; @@ -13,4 +15,6 @@ public function getValuesUsing(): string; public function getKeysUsing(): string; public function getModel(): string; + + public function getQuery(): Builder; } From 7b2d82410a69695103a3959a5d423c9e4f0051cf Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Thu, 18 Apr 2024 19:22:35 +0330 Subject: [PATCH 2/8] feat: update FieldsContract --- src/Fields/FieldsContract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fields/FieldsContract.php b/src/Fields/FieldsContract.php index 656590ea..de674578 100644 --- a/src/Fields/FieldsContract.php +++ b/src/Fields/FieldsContract.php @@ -218,7 +218,7 @@ public static function getFieldCollectionItemsList(Field | FieldPreset | array $ if (class_exists($zeusField->options['dataSource'])) { //@phpstan-ignore-next-line $dataSourceClass = new $zeusField->options['dataSource']; - $getCollection = $dataSourceClass->getModel()::pluck( + $getCollection = $dataSourceClass->getQuery()->pluck( $dataSourceClass->getValuesUsing(), $dataSourceClass->getKeysUsing() ); From bf60aa12bfd3bd4376b2928dcdf8583b0ab48474 Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Thu, 18 Apr 2024 19:25:52 +0330 Subject: [PATCH 3/8] feat: add getQuery method to ZeusDataSources stub --- stubs/ZeusDataSources.stub | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stubs/ZeusDataSources.stub b/stubs/ZeusDataSources.stub index 6ab99fd6..9e72f60f 100644 --- a/stubs/ZeusDataSources.stub +++ b/stubs/ZeusDataSources.stub @@ -3,6 +3,7 @@ namespace {{ namespace }}; use LaraZeus\Bolt\DataSources\DataSourceContract; +use Illuminate\Database\Eloquent\Builder; class {{ class }} extends DataSourceContract { @@ -25,5 +26,10 @@ class {{ class }} extends DataSourceContract { return \App\Models\{{ class }}::class; } + + public function getQuery(): Builder + { + return resolve($this->getModel())->query(); + } } From 2d6151289b2a1b100cb9c6d57b58ecdc71e04952 Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Fri, 19 Apr 2024 12:57:42 +0330 Subject: [PATCH 4/8] feat: add Collection type for getQuery method --- src/Contracts/DataSource.php | 3 ++- stubs/ZeusDataSources.stub | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Contracts/DataSource.php b/src/Contracts/DataSource.php index 4c005530..923b25c7 100644 --- a/src/Contracts/DataSource.php +++ b/src/Contracts/DataSource.php @@ -3,6 +3,7 @@ namespace LaraZeus\Bolt\Contracts; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Collection; interface DataSource { @@ -16,5 +17,5 @@ public function getKeysUsing(): string; public function getModel(): string; - public function getQuery(): Builder; + public function getQuery(): Builder | Collection; } diff --git a/stubs/ZeusDataSources.stub b/stubs/ZeusDataSources.stub index 9e72f60f..2a3d1488 100644 --- a/stubs/ZeusDataSources.stub +++ b/stubs/ZeusDataSources.stub @@ -4,6 +4,7 @@ namespace {{ namespace }}; use LaraZeus\Bolt\DataSources\DataSourceContract; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Collection; class {{ class }} extends DataSourceContract { @@ -27,7 +28,7 @@ class {{ class }} extends DataSourceContract return \App\Models\{{ class }}::class; } - public function getQuery(): Builder + public function getQuery(): Builder | Collection { return resolve($this->getModel())->query(); } From bc79223af1d7a1cb74a85238b0efc699ed5d82e7 Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Sun, 21 Apr 2024 23:14:52 +0330 Subject: [PATCH 5/8] feat: add getQuery to DataSourceContract and remove from ZeuseDataSource stub --- src/DataSources/DataSourceContract.php | 7 +++++++ stubs/ZeusDataSources.stub | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/DataSources/DataSourceContract.php b/src/DataSources/DataSourceContract.php index c409f317..405b3f2e 100644 --- a/src/DataSources/DataSourceContract.php +++ b/src/DataSources/DataSourceContract.php @@ -4,6 +4,8 @@ use Illuminate\Contracts\Support\Arrayable; use LaraZeus\Bolt\Contracts\DataSource; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Collection; abstract class DataSourceContract implements Arrayable, DataSource { @@ -14,6 +16,11 @@ public function getSort(): int return 1; } + public function getQuery(): Builder | Collection + { + return resolve($this->getModel())->query(); + } + public function toArray(): array { return [ diff --git a/stubs/ZeusDataSources.stub b/stubs/ZeusDataSources.stub index 2a3d1488..7c896e02 100644 --- a/stubs/ZeusDataSources.stub +++ b/stubs/ZeusDataSources.stub @@ -27,10 +27,5 @@ class {{ class }} extends DataSourceContract { return \App\Models\{{ class }}::class; } - - public function getQuery(): Builder | Collection - { - return resolve($this->getModel())->query(); - } } From e25431f983e0d1e952aff96349539a25e7e65a3d Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Sun, 21 Apr 2024 23:16:27 +0330 Subject: [PATCH 6/8] feat: update FieldsContract --- src/Fields/FieldsContract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fields/FieldsContract.php b/src/Fields/FieldsContract.php index de674578..763a8400 100644 --- a/src/Fields/FieldsContract.php +++ b/src/Fields/FieldsContract.php @@ -163,7 +163,7 @@ public function getCollectionsValuesForResponse(Field $field, FieldResponse $res ->join(', '); } else { $dataSourceClass = new $field->options['dataSource']; - $response = $dataSourceClass->getModel()::query() + $response = $dataSourceClass->getQuery() ->whereIn($dataSourceClass->getKeysUsing(), $response) ->pluck($dataSourceClass->getValuesUsing()) ->join(', '); From 9a2906c572da43f25337a61412d80c0169a88553 Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Sun, 21 Apr 2024 23:22:40 +0330 Subject: [PATCH 7/8] feat: update ZeusDataSource file --- stubs/ZeusDataSources.stub | 2 -- 1 file changed, 2 deletions(-) diff --git a/stubs/ZeusDataSources.stub b/stubs/ZeusDataSources.stub index 7c896e02..6ab99fd6 100644 --- a/stubs/ZeusDataSources.stub +++ b/stubs/ZeusDataSources.stub @@ -3,8 +3,6 @@ namespace {{ namespace }}; use LaraZeus\Bolt\DataSources\DataSourceContract; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Support\Collection; class {{ class }} extends DataSourceContract { From 130bba2dbc64011888a10d296b68380eb94c9199 Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Sun, 21 Apr 2024 23:23:03 +0330 Subject: [PATCH 8/8] styles: fix the codes styles --- src/DataSources/DataSourceContract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataSources/DataSourceContract.php b/src/DataSources/DataSourceContract.php index 405b3f2e..e3d77ecf 100644 --- a/src/DataSources/DataSourceContract.php +++ b/src/DataSources/DataSourceContract.php @@ -3,9 +3,9 @@ namespace LaraZeus\Bolt\DataSources; use Illuminate\Contracts\Support\Arrayable; -use LaraZeus\Bolt\Contracts\DataSource; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; +use LaraZeus\Bolt\Contracts\DataSource; abstract class DataSourceContract implements Arrayable, DataSource {