From 57f2679903300d2dc8dc4db96ec6740340ebd59d Mon Sep 17 00:00:00 2001 From: Samgu Lee Date: Mon, 30 Dec 2024 18:25:19 +0900 Subject: [PATCH] Add new functions for Laravel Nova (#74) * Add resources and remove Korean version in README file * Add the function of making Nova resource file * Add laravel commands for Nova * Update README file --- README.ko.md | 277 ------------------ README.md | 81 ++++- bin/console | 2 + dist/app/Nova/.gitignore | 2 + src/Column.php | 24 ++ src/Command/GenerateNovaCommand.php | 78 +++++ src/Generators/NovaResourceGenerator.php | 93 ++++++ src/Interfaces/ResolverInterface.php | 7 + src/Laravel/Commands/GenerateNovaCommand.php | 55 ++++ src/Resolvers/BigintResolver.php | 13 + src/Resolvers/BinaryResolver.php | 7 + src/Resolvers/BitResolver.php | 7 + src/Resolvers/BlobResolver.php | 7 + src/Resolvers/BoolResolver.php | 7 + src/Resolvers/CharResolver.php | 7 + src/Resolvers/DateResolver.php | 7 + src/Resolvers/DateTimeTzResolver.php | 7 + src/Resolvers/DatetimeResolver.php | 7 + src/Resolvers/DecimalResolver.php | 6 + src/Resolvers/DoubleResolver.php | 6 + src/Resolvers/EnumResolver.php | 8 + src/Resolvers/FloatResolver.php | 6 + src/Resolvers/GeometryResolver.php | 7 + src/Resolvers/IdResolver.php | 5 + src/Resolvers/InetResolver.php | 7 + src/Resolvers/IntResolver.php | 13 + src/Resolvers/JsonResolver.php | 7 + src/Resolvers/JsonbResolver.php | 7 + src/Resolvers/LongblobResolver.php | 7 + src/Resolvers/LongtextResolver.php | 7 + src/Resolvers/MacaddressResolver.php | 7 + src/Resolvers/MediumblobResolver.php | 7 + src/Resolvers/MediumintResolver.php | 7 + src/Resolvers/MediumtextResolver.php | 7 + src/Resolvers/MorphsResolver.php | 7 + src/Resolvers/MultipointResolver.php | 7 + src/Resolvers/RemembertokenResolver.php | 7 + src/Resolvers/Resolver.php | 9 + src/Resolvers/SmallintResolver.php | 7 + src/Resolvers/TextResolver.php | 7 + src/Resolvers/TimeResolver.php | 6 + src/Resolvers/TimeTzResolver.php | 6 + src/Resolvers/TimestampResolver.php | 6 + src/Resolvers/TinyblobResolver.php | 5 + src/Resolvers/TinyintResolver.php | 9 + src/Resolvers/TinytextResolver.php | 7 + src/Resolvers/UlidResolver.php | 15 + src/Resolvers/UlidmorphsResolver.php | 10 + src/Resolvers/UuidResolver.php | 7 + src/Resolvers/UuidmorphsResolver.php | 5 + src/Resolvers/VarbinaryResolver.php | 7 + src/Resolvers/VarcharResolver.php | 6 + src/Resolvers/YearResolver.php | 7 + src/Support/Inflector.php | 20 ++ src/Support/Path.php | 12 + src/Table.php | 26 ++ stubs/NovaResource.stub | 84 ++++++ tests/Unit/Resolvers/BigintResolverTest.php | 15 + tests/Unit/Resolvers/BoolResolverTest.php | 9 + tests/Unit/Resolvers/BooleanResolverTest.php | 9 + tests/Unit/Resolvers/CharResolverTest.php | 9 + tests/Unit/Resolvers/DateResolverTest.php | 9 + tests/Unit/Resolvers/DatetimeResolverTest.php | 9 + tests/Unit/Resolvers/DecimalResolverTest.php | 9 + tests/Unit/Resolvers/DoubleResolverTest.php | 9 + tests/Unit/Resolvers/FloatResolverTest.php | 9 + tests/Unit/Resolvers/IdResolverTest.php | 7 + tests/Unit/Resolvers/IntResolverTest.php | 9 + tests/Unit/Resolvers/IntegerResolverTest.php | 9 + tests/Unit/Resolvers/JsonResolverTest.php | 9 + tests/Unit/Resolvers/LongtextResolverTest.php | 9 + .../Unit/Resolvers/MacaddressResolverTest.php | 9 + .../Unit/Resolvers/MediumintResolverTest.php | 9 + .../Unit/Resolvers/MediumtextResolverTest.php | 9 + .../Resolvers/RemembertokenResolverTest.php | 9 + tests/Unit/Resolvers/SmallintResolverTest.php | 9 + tests/Unit/Resolvers/StringResolverTest.php | 9 + tests/Unit/Resolvers/TextResolverTest.php | 9 + tests/Unit/Resolvers/TimeResolverTest.php | 9 + .../Unit/Resolvers/TimestampResolverTest.php | 9 + tests/Unit/Resolvers/TinyintResolverTest.php | 9 + tests/Unit/Resolvers/TinytextResolverTest.php | 9 + tests/Unit/Resolvers/UlidResolverTest.php | 9 + .../UnsignedBigIntegerResolverTest.php | 9 + .../Resolvers/UnsignedIntegerResolverTest.php | 9 + .../UnsignedMediumIntegerResolverTest.php | 9 + .../UnsignedSmallIntegerResolverTest.php | 9 + .../UnsignedTinyIntegerResolverTest.php | 9 + tests/Unit/Resolvers/UuidResolverTest.php | 9 + tests/Unit/Resolvers/VarcharResolverTest.php | 9 + tests/Unit/Resolvers/YearResolverTest.php | 9 + 91 files changed, 1115 insertions(+), 279 deletions(-) delete mode 100644 README.ko.md create mode 100644 dist/app/Nova/.gitignore create mode 100644 src/Command/GenerateNovaCommand.php create mode 100644 src/Generators/NovaResourceGenerator.php create mode 100644 src/Laravel/Commands/GenerateNovaCommand.php create mode 100644 stubs/NovaResource.stub diff --git a/README.ko.md b/README.ko.md deleted file mode 100644 index 86ede6f..0000000 --- a/README.ko.md +++ /dev/null @@ -1,277 +0,0 @@ -# Xeed - 라라벨 리소스 제네레이터 - -[English 👈](README.md) - -[![code-style](https://github.com/cable8mm/xeed/actions/workflows/code-style.yml/badge.svg)](https://github.com/cable8mm/xeed/actions/workflows/code-style.yml) -[![run-tests](https://github.com/cable8mm/xeed/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cable8mm/xeed/actions/workflows/run-tests.yml) -[![Packagist Version](https://img.shields.io/packagist/v/cable8mm/xeed)](https://packagist.org/packages/cable8mm/xeed) -[![Packagist Downloads](https://img.shields.io/packagist/dt/cable8mm/xeed)](https://packagist.org/packages/cable8mm/xeed/stats) -[![Packagist Dependency Version](https://img.shields.io/packagist/dependency-v/cable8mm/xeed/php)](https://packagist.org/packages/cable8mm/xeed) -![Packagist Dependency Version](https://img.shields.io/packagist/dependency-v/cable8mm/xeed/symfony%2Fconsole) -[![Packagist Stars](https://img.shields.io/packagist/stars/cable8mm/xeed)](https://github.com/cable8mm/xeed/stargazers) -[![Packagist License](https://img.shields.io/packagist/l/cable8mm/xeed)](https://github.com/cable8mm/xeed/blob/main/LICENSE.md) - -Xeed는 기존 데이터베이스 테이블에서 가져온 데이터를 기반으로 Laravel용 새로운 모델, 시드, 데이터베이스 시드, 팩토리 및 마이그레이션 파일을 생성하는 데 사용됩니다. - -> [!TIP] -> 이 프로그램은 `php artisan xeed:*` 라라벨 명령어와 `bin/console *` 독립 명령어로 모두 작동할 수 있으며, 100% 동일한 기능을 제공합니다. 따라서 여러분은 여러분의 Laravel 프로젝트 내에서 사용하거나 독립적인 애플리케이션으로 사용할 수 있습니다. - -웹 상에서 API 문서를 제공합니다. 자세한 내용은 https://www.palgle.com/xeed/ 에서 확인하십시오. ❤️ - -### 기능 - -- [x] 데이터베이스 테스트 지원 -- [x] Laravel을 위한 모델 생성 -- [x] Laravel을 위한 시드 파일 생성 -- [x] Laravel을 위한 데이터베이스 시드 파일 생성 -- [x] Laravel을 위한 팩토리 생성 -- [x] Laravel을 위한 마이그레이션 생성 -- [x] Laravel 다중 및 예약된 열 지원 -- [x] Laravel 통합 -- [x] MySQL, SQLite 그리고 PostgreSQL 지원 - -### 지원 및 테스트 - -![MySQL 지원](https://img.shields.io/badge/MySQL-4479A1?logo=mysql&logoColor=white) -![SQLite 지원](https://img.shields.io/badge/SQLite-07405e?logo=sqlite&logoColor=white) -![PostgreSQL 지원](https://img.shields.io/badge/PostgreSQL-Beta-316192?&logo=postgresql&logoColor=white) -![PHP 8.0.2+ 지원](https://img.shields.io/badge/PHP-8.0.2%2B-777BB4?logo=php&logoColor=white) -![PHP 8.1.0+ 지원](https://img.shields.io/badge/PHP-8.1.0%2B-777BB4?logo=php&logoColor=white) -![PHP 8.2.0+ 지원](https://img.shields.io/badge/PHP-8.2.0%2B-777BB4?logo=php&logoColor=white) -![PHP 8.3.0+ 지원](https://img.shields.io/badge/PHP-8.3.0%2B-777BB4?logo=php&logoColor=white) - -> [!CAUTION] -> PostgreSQL은 Beta 지원이며, 문제가 발생할 경우 깃헙 이슈를 통해서 리포팅 해 주세요. - -### 미리보기 - -Laravel: - -![Preview](https://github.com/cable8mm/cabinet/blob/main/xeed-laravel-preview.gif?raw=true) - -Standalone: - -![Preview](https://github.com/cable8mm/cabinet/blob/main/xeed-preview.gif?raw=true) - -## 설치 - -```shell tab=Laravel -composer require cable8mm/xeed --dev -# For Laravel -``` - -```shell tab=Standalone -composer create-project cable8mm/xeed -# For Standalone -``` - -> [!IMPORTANT] -> 그리고 `.env` 파일을 편집하여 연결해야 하는 데이터베이스를 구성하십시오. 필요할 때마다 수동으로 `.env.example`을 `.env`로 복사할 수 있습니다. - -## 사용법 - -### `모델` 생성 - -```shell tab=Laravel -php artisan xeed:models -# `app/Models` 폴더에 모든 모델 생성 -``` - -```shell tab=Standalone -bin/console models -# `dist/app/Models` 폴더에 모든 모델 생성 -``` - -### `시드` 생성 - -```shell tab=Laravel -php artisan xeed:seeders -# `database/seeders` 폴더에 모든 시드 생성 -``` - -```shell tab=Standalone -bin/console seeders -# `dist/database/seeders` 폴더에 모든 시드 생성 -``` - -### `DatabaseSeeder` 생성 - -```shell tab=Laravel -php artisan xeed:database -# `database/seeders` 폴더에 데이터베이스 시드 생성 -``` - -```shell tab=Standalone -bin/console database -# `dist/database/seeders` 폴더에 데이터베이스 시드 생성 -``` - -### `팩토리` 생성 - -```shell tab=Laravel -php artisan xeed:factories -# `database/factories' 폴더에 모든 팩토리 생성 -``` - -```shell tab=Standalone -bin/console factories -# `dist/database/factories' 폴더에 모든 팩토리 생성 -``` - -### `마이그레이션` 생성 - -```shell tab=Laravel -php artisan xeed:migrations -# `database/migrations' 폴더에 모든 마이그레이션 파일 생성 -``` - -```shell tab=Standalone -bin/console migrations -# `dist/database/migrations' 폴더에 모든 마이그레이션 파일 생성 -``` - -생성된 파일은 라라벨 프로젝트와 동일한 폴더에 저장됩니다. `dist` 폴더를 확인하세요. - -## 기여 방법 - -### 개발 - -Xeed에는 내장된 SQLite 데이터베이스가 있어 직접 데이터베이스가 필요하지 않고 쉽게 기여할 수 있습니다. 테스트 목적으로 새 파일을 만들고 활용하면 됩니다. - -```sh -touch database/database.sqlite -# SQLite 데이터베이스를 위한 새 파일 생성 -``` - -그리고, - -```sh -composer test -# 테스트 실행 -``` - -### 데이터베이스 - -마이그레이션 및 팩토리의 경우 모든 데이터베이스 필드 유형에 대한 테스트를 실행해야 할 때 다음 명령을 사용하십시오. - -```sh -bin/console xeed -# 'xeeds' 테이블을 데이터베이스에 가져오기 - -bin/console xeed drop -# 데이터베이스에서 'xeeds' 테이블 삭제 -``` - -생성된 파일을 확인하려면 다음 위치를 참조하십시오. `resources/tests` 이 폴더에 파일이 저장됩니다. - -### 유용한 명령 - -이 패키지를 직접 테스트할 것이라면 다음 명령을 사용하여 생성된 파일을 정리합니다. - -```shell tab=Laravel -php artisan xeed:clean -# 생성된 파일, 시드, 모델, 팩토리 및 마이그레이션 파일 정리 -#=> 아래 참조 -Please select directory for you to want to clean. - [0] seeder - [1] model - [2] factory - [3] migration - [4] all - [5] exit -``` - -```shell tab=Standalone -bin/console clean -# 생성된 파일, 시드, 모델, 팩토리 및 마이그레이션 파일 정리 -#=> 아래 참조 -Please select directory for you to want to clean. - [0] seeder - [1] model - [2] factory - [3] migration - [4] all - [5] exit -``` - -### 버그 보고 및 풀 리퀘스트 제출 - -버그 보고서 및 풀 리퀘스트를 작성하는 기회는 저를 기쁘게 합니다. 필요할 때마다 기여하고 풀 리퀘스트를 제출하십시오. - -## 포맷팅 - -```bash -composer lint -# 모든 파일을 PSR-12에 따르도록 수정합니다. - -composer inspect -# 모든 파일을 PSR-12을 준수하는지 확인합니다. -``` - -## 테스트 - -사용된 내장 SQLite 데이터베이스는 사용자의 데이터베이스가 아니라는 점을 명심하십시오. 데이터에 손상을 줄 염려가 없습니다. - -```shell tab=Laravel -composer testpack -# 라라벨 커맨드를 포함한 모든 테스트 -``` - -```shell tab=Standalone -composer test -# 라라벨 커맨드를 제외한 모든 테스트 -``` - -### 변경 내역 - -최근 변경된 내용에 대한 자세한 정보는 [CHANGELOG](CHANGELOG.md)를 참조해주세요. - -## 기여 - -더 자세한 내용은 [CONTRIBUTING](CONTRIBUTING.md)를 참조해주세요. - -아래 내용은 기여하는 데 도움이 될 수 있습니다. - -Xeed에는 내장된 SQLite 데이터베이스가 있어 별도의 데이터베이스가 필요하지 않고도 쉽게 기여할 수 있습니다. 테스트 목적으로 새 파일을 만들고 활용하기만 하면 됩니다. - -```shell -touch database/database.sqlite -# SQLite 데이터베이스를 위한 새로운 빈 파일을 만드세요 -``` - -그 후, - -```shell -composer test -# 테스트 샐행 -``` - -### 데이터베이스 시드 - -마이그레이션과 팩토리를 사용할 때, 모든 데이터베이스 필드 유형에 대한 테스트를 실행해야 할 때는 다음 명령어를 사용하세요. - -```shell tab=Laravel -php artisan xeed -# 데이터베이스에 'xeeds' 테이블 임포트 - -php artisan xeed drop -# 데이터베이스에 'xeeds' 테이블 삭제 -``` - -```shell tab=Standalone -bin/console xeed -# 데이터베이스에 'xeeds' 테이블 임포트 - -bin/console xeed drop -# 데이터베이스에 'xeeds' 테이블 삭제 -``` - -모든 데이터베이스 필드 유형에 대해 마이그레이션 파일을 활용하려면 다음 위치를 참조하세요: `database/*.sql`. 이러한 파일들은 지정된 폴더에 저장됩니다. - -## 크레디트 - -- [Samgu Lee](https://github.com/cable8mm) - -## 라이센스 - -Xeed 프로젝트는 [MIT 라이센스](LICENSE.md)에 따라 오픈 소스 소프트웨어로 라이센스가 부여됩니다. diff --git a/README.md b/README.md index 2a9c159..0de4dd6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Xeed - Resources Generator for Laravel -[한글(Korean) 👈](README.ko.md) - [![code-style](https://github.com/cable8mm/xeed/actions/workflows/code-style.yml/badge.svg)](https://github.com/cable8mm/xeed/actions/workflows/code-style.yml) [![run-tests](https://github.com/cable8mm/xeed/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cable8mm/xeed/actions/workflows/run-tests.yml) [![Packagist Version](https://img.shields.io/packagist/v/cable8mm/xeed)](https://packagist.org/packages/cable8mm/xeed) @@ -24,6 +22,7 @@ We have provided the API Documentation on the web. For more information, please - [x] Database testing is supported - [x] Generate models for Laravel - [x] Generate seed files for Laravel +- [x] Generate Laravel Nova resources files for Laravel - [x] Generate database seed files for Laravel - [x] Generate factories for Laravel - [x] Generate migrations for Laravel @@ -200,6 +199,18 @@ bin/console relations -m The generated relations are named using laravels convention. Some names may be duplicated +### Generate `NovaResources` + +```shell tab=Laravel +php artisan xeed:nova +# Add the Laravel Nova resources to all tables in `app/Nova` folder +``` + +```shell tab=Standalone +bin/console nova-fields +# Add the Laravel Nova resources to all tables in `dist/app/Nova` folder +``` + ### Helpful commands If you are going to test this package yourself, then you would use the following commands to clean up generated files. @@ -304,6 +315,72 @@ Utilize migration files for all database field types by referring to the followi You can utilize `testorchestral/testbench` to execute tests. When running Laravel commands, the generated files are saved in the `vendor/orchestra/testbench-core/laravel/database` folder. +## Resources + +Laravel columns **description** for mysql: + +|Available Column Types |Field |Type |Null|Key|Default|Extra | +|--------------------------------------------------------|------------------------|---------------------------|----|---|-------|--------------| +|id() |id |bigint unsigned |NO |PRI| |auto_increment| +|bigInteger('big_integer') |big_integer |bigint |NO | | | | +|binary('binary') |binary |blob |NO | | | | +|boolean('boolean') |boolean |tinyint(1) |NO | | | | +|char('char', length: 100) |char |char(100) |NO | | | | +|dateTimeTz('date_time_tz', precision: 0) |date_time_tz |datetime |NO | | | | +|dateTime('date_time', precision: 0) |date_time |datetime |NO | | | | +|date('date') |date |date |NO | | | | +|decimal('decimal', total: 8, places: 2) |decimal |decimal(8,2) |NO | | | | +|double('double') |double |double |NO | | | | +|enum('enum', \['easy', 'hard'\]) |enum |enum('easy','hard') |NO | | | | +|float('float', precision: 53) |float |double |NO | | | | +|foreignId('foreign_id') |foreign_id |bigint unsigned |NO | | | | +|foreignUlid('foreign_ulid') |foreign_ulid |char(26) |NO | | | | +|foreignUuid('foreign_uuid') |foreign_uuid |char(36) |NO | | | | +|geometry('geometry', subtype: 'point', srid: 0) |geometry |point |NO | | | | +|integer('integer') |integer |int |NO | | | | +|ipAddress('ip_address') |ip_address |varchar(45) |NO | | | | +|json('json') |json |json |NO | | | | +|jsonb('jsonb') |jsonb |json |NO | | | | +|longText('long_text') |long_text |longtext |NO | | | | +|macAddress('mac_address') |mac_address |varchar(17) |NO | | | | +|mediumInteger('medium_integer') |medium_integer |mediumint |NO | | | | +|mediumText('medium_text') |medium_text |mediumtext |NO | | | | +|morphs('morph') |morph_type |varchar(255) |NO |MUL| | | +|_Ditto make 2 fields_ |morph_id |bigint unsigned |NO | | | | +|nullableTimestamps(precision: 0) |created_at |timestamp |YES | | | | +|_Ditto make 2 fields_ |updated_at |timestamp |YES | | | | +|nullableMorphs('nullable_morph') |nullable_morph_type |varchar(255) |YES |MUL| | | +|_Ditto make 2 fields_ |nullable_morph_id |bigint unsigned |YES | | | | +|nullableUlidMorphs('nullable_ulid_morph') |nullable_ulid_morph_type|varchar(255) |YES |MUL| | | +|_Ditto make 2 fields_ |nullable_ulid_morph_id |char(26) |YES | | | | +|nullableUuidMorphs('nullable_uuid_morph') |nullable_uuid_morph_type|varchar(255) |YES |MUL| | | +|_Ditto make 2 fields_ |nullable_uuid_morph_id |char(36) |YES | | | | +|rememberToken() |remember_token |varchar(100) |YES | | | | +|set('set', \['strawberry', 'vanilla'\]) |set |set('strawberry','vanilla')|NO | | | | +|smallInteger('small_integer') |small_integer |smallint |NO | | | | +|softDeletesTz('soft_delete_tz', precision: 0) |soft_delete_tz |timestamp |YES | | | | +|softDeletes('soft_delete', precision: 0) |soft_delete |timestamp |YES | | | | +|string('string', length: 100) |string |varchar(100) |NO | | | | +|text('text') |text |text |NO | | | | +|time('time_tz', 0) |time_tz |time |NO | | | | +|time('time', 0) |time |time |NO | | | | +|timestampTz('timestamp_tz', precision: 0) |timestamp_tz |timestamp |NO | | | | +|timestamp('timestamp', precision: 0) |timestamp |timestamp |NO | | | | +|tinyInteger('tiny_integer') |tiny_integer |tinyint |NO | | | | +|tinyText('tiny_text') |tiny_text |tinytext |NO | | | | +|unsignedBigInteger('unsigned_big_integer') |unsigned_big_integer |bigint unsigned |NO | | | | +|unsignedInteger('unsigned_integer') |unsigned_integer |int unsigned |NO | | | | +|unsignedMediumInteger('unsigned_medium_integer')|unsigned_medium_integer |mediumint unsigned |NO | | | | +|unsignedSmallInteger('unsigned_small_integer') |unsigned_small_integer |smallint unsigned |NO | | | | +|unsignedTinyInteger('unsigned_tiny_integer') |unsigned_tiny_integer |tinyint unsigned |NO | | | | +|ulidMorphs('ulid_morph') |ulid_morph_type |varchar(255) |NO |MUL| | | +|_Ditto make 2 fields_ |ulid_morph_id |char(26) |NO | | | | +|uuidMorphs('uuid_morph') |uuid_morph_type |varchar(255) |NO |MUL| | | +|_Ditto make 2 fields_ |uuid_morph_id |char(36) |NO | | | | +|ulid('ulid') |ulid |char(26) |NO | | | | +|uuid('uuid') |uuid |char(36) |NO | | | | +|year('year') |year |year |NO | | | | + ## Credits - [Samgu Lee](https://github.com/cable8mm) diff --git a/bin/console b/bin/console index 3d7358f..8855917 100755 --- a/bin/console +++ b/bin/console @@ -9,6 +9,7 @@ use Cable8mm\Xeed\Command\GenerateFactoriesCommand; use Cable8mm\Xeed\Command\GenerateFakerSeedersCommand; use Cable8mm\Xeed\Command\GenerateMigrationsCommand; use Cable8mm\Xeed\Command\GenerateModelsCommand; +use Cable8mm\Xeed\Command\GenerateNovaCommand; use Cable8mm\Xeed\Command\GenerateRelationsCommand; use Cable8mm\Xeed\Command\GenerateSeedersCommand; use Cable8mm\Xeed\Command\ImportXeedCommand; @@ -27,5 +28,6 @@ $application->add(new GenerateFactoriesCommand()); $application->add(new GenerateMigrationsCommand()); $application->add(new GenerateFakerSeedersCommand()); $application->add(new GenerateRelationsCommand()); +$application->add(new GenerateNovaCommand()); $application->run(); diff --git a/dist/app/Nova/.gitignore b/dist/app/Nova/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/dist/app/Nova/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/src/Column.php b/src/Column.php index 90d9094..101a71e 100644 --- a/src/Column.php +++ b/src/Column.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed; +use Cable8mm\Xeed\Support\Inflector; use Stringable; /** @@ -113,6 +114,29 @@ public function migration(): string return ResolverSelector::of($this)->migration(); } + /** + * Get the row string for migration file, then return the string for migration class. + * + * @return string The method returns a Migration class row string + */ + public function novaField(): string + { + return ResolverSelector::of($this)->nova(); + } + + /** + * Get the title for Nova field title from column name. + * + * @return string The method returns the title for Nova field title + * + * @example echo (new Column(['username', 'varchar']))->title(); + * //=> Username + */ + public function title(): string + { + return Inflector::title($this->field); + } + /** * Class magic method to get the instance information for a Exception * diff --git a/src/Command/GenerateNovaCommand.php b/src/Command/GenerateNovaCommand.php new file mode 100644 index 0000000..56fbf6e --- /dev/null +++ b/src/Command/GenerateNovaCommand.php @@ -0,0 +1,78 @@ +safeLoad(); + + $this + ->addOption( + 'force', + 'f', + InputOption::VALUE_OPTIONAL, + 'Are files forcibly deleted even if they exist?', + false + )->addOption( + 'table', + 't', + InputOption::VALUE_OPTIONAL, + 'Are you generating the specific table with the nova field?', + null + ); + } + + /** + * Run the console command. + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $force = $input->getOption('force') ?? true; + + $table = $input->getOption('table'); + + $tables = is_null($table) + ? Xeed::getInstance()->attach()->getTables() + : Xeed::getInstance()->attach($table)->getTables(); + + foreach ($tables as $table) { + try { + NovaResourceGenerator::make($table)->run(force: $force); + + $output->writeln(''.Path::nova().DIRECTORY_SEPARATOR.$table->nova().'.php have been generated.'.''); + } catch (\RuntimeException $e) { + $output->writeln(' => '.$e->getMessage().''); + } + } + + $output->writeln('generate-nova-fields command executed successfully.'); + + return Command::SUCCESS; + } +} diff --git a/src/Generators/NovaResourceGenerator.php b/src/Generators/NovaResourceGenerator.php new file mode 100644 index 0000000..bd68116 --- /dev/null +++ b/src/Generators/NovaResourceGenerator.php @@ -0,0 +1,93 @@ +destination = Path::nova(); + } + + $this->stub = File::system()->read(Path::stub().DIRECTORY_SEPARATOR.'NovaResource.stub'); + } + + /** + * {@inheritDoc} + */ + public function run(bool $force = false): void + { + $novaFieldsString = ''; + foreach ($this->table->getColumns() as $column) { + $novaFieldsString .= self::INTENT.$column->novaField().PHP_EOL; + } + $novaFieldsString = rtrim($novaFieldsString, PHP_EOL.PHP_EOL); + + preg_match_all('/([a-zA-Z]+):/m', $novaFieldsString, $classUses); + $uniqueClassUses = array_unique($classUses[1]); + asort($uniqueClassUses); + + $classUsesString = ''; + foreach ($uniqueClassUses as $classUse) { + $classUsesString .= 'use Laravel\\Nova\\Fields\\'.$classUse.';'.PHP_EOL; + } + $classUsesString = rtrim($classUsesString, PHP_EOL); + + $seederClass = str_replace( + [ + '{class_uses}', + '{nova_class_name}', + '{model_class_name}', + '{table_title}', + '{nova_fields}', + ], + [ + $classUsesString, + $this->table->nova(), + $this->table->model(), + $this->table->title(), + $novaFieldsString, + ], + $this->stub + ); + + File::system()->write( + $this->destination.DIRECTORY_SEPARATOR.$this->table->nova('.php'), + $seederClass, + $force + ); + } + + /** + * {@inheritDoc} + */ + public static function make( + Table $table, + ?string $namespace = null, + ?string $destination = null + ): static { + return new self($table, $namespace, $destination); + } +} diff --git a/src/Interfaces/ResolverInterface.php b/src/Interfaces/ResolverInterface.php index aea0772..e0a44fc 100644 --- a/src/Interfaces/ResolverInterface.php +++ b/src/Interfaces/ResolverInterface.php @@ -20,4 +20,11 @@ public function fake(): string; * @return string The method returns a Migration file row string */ public function migration(): string; + + /** + * Get the row string for Nova resource file, then return the string for Nova resource class. + * + * @return string The method returns a Nova resource file row field string + */ + public function nova(): ?string; } diff --git a/src/Laravel/Commands/GenerateNovaCommand.php b/src/Laravel/Commands/GenerateNovaCommand.php new file mode 100644 index 0000000..7b640c3 --- /dev/null +++ b/src/Laravel/Commands/GenerateNovaCommand.php @@ -0,0 +1,55 @@ +option('force') ?? false; + + $table = $this->option('table'); + + $tables = is_null($table) + ? Xeed::getInstance()->attach()->getTables() + : Xeed::getInstance()->attach($table)->getTables(); + + foreach ($tables as $table) { + try { + NovaResourceGenerator::make( + $table, + destination: app_path('Nova') + )->run(force: $force); + + $this->info(app_path('Nova').DIRECTORY_SEPARATOR.$table->nova().'.php has been generated.'); + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + } + + return Command::SUCCESS; + } +} diff --git a/src/Resolvers/BigintResolver.php b/src/Resolvers/BigintResolver.php index 4959477..60c9517 100644 --- a/src/Resolvers/BigintResolver.php +++ b/src/Resolvers/BigintResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * BIGINT(size) * @@ -30,4 +32,15 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + if ($this->column->field === 'id') { + $novaResourceField = 'ID::make()->sortable(),'; + } else { + $novaResourceField = 'Number::make(\''.Inflector::title($this->column->field).'\'),'; + } + + return $novaResourceField; + } } diff --git a/src/Resolvers/BinaryResolver.php b/src/Resolvers/BinaryResolver.php index 1318bd3..07c6581 100644 --- a/src/Resolvers/BinaryResolver.php +++ b/src/Resolvers/BinaryResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * BINARY(size) * @@ -22,4 +24,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/BitResolver.php b/src/Resolvers/BitResolver.php index 327acab..50cd5c0 100644 --- a/src/Resolvers/BitResolver.php +++ b/src/Resolvers/BitResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * BIT(size) * @@ -23,4 +25,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Boolean::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/BlobResolver.php b/src/Resolvers/BlobResolver.php index 647354e..f862dc2 100644 --- a/src/Resolvers/BlobResolver.php +++ b/src/Resolvers/BlobResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * BLOB(size) * @@ -21,4 +23,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/BoolResolver.php b/src/Resolvers/BoolResolver.php index 8d6e464..1c2b42b 100644 --- a/src/Resolvers/BoolResolver.php +++ b/src/Resolvers/BoolResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * BOOL * @@ -20,4 +22,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Boolean::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/CharResolver.php b/src/Resolvers/CharResolver.php index 6791382..4088039 100644 --- a/src/Resolvers/CharResolver.php +++ b/src/Resolvers/CharResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * CHAR(size) * @@ -24,4 +26,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/DateResolver.php b/src/Resolvers/DateResolver.php index e20a7e6..26aa715 100644 --- a/src/Resolvers/DateResolver.php +++ b/src/Resolvers/DateResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * DATE * @@ -21,4 +23,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Date::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/DateTimeTzResolver.php b/src/Resolvers/DateTimeTzResolver.php index f834235..265bdb7 100644 --- a/src/Resolvers/DateTimeTzResolver.php +++ b/src/Resolvers/DateTimeTzResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * timestamp with time zone * @@ -20,4 +22,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'DateTime::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/DatetimeResolver.php b/src/Resolvers/DatetimeResolver.php index c9e87f2..cecaed1 100644 --- a/src/Resolvers/DatetimeResolver.php +++ b/src/Resolvers/DatetimeResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * DATETIME(fsp) * @@ -28,4 +30,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'DateTime::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/DecimalResolver.php b/src/Resolvers/DecimalResolver.php index 7e9b0c0..8ae66f5 100644 --- a/src/Resolvers/DecimalResolver.php +++ b/src/Resolvers/DecimalResolver.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; use Cable8mm\Xeed\Types\Bracket; /** @@ -32,4 +33,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Number::make(\''.Inflector::title($this->column->field).'\')->step(\'any\'),'; + } } diff --git a/src/Resolvers/DoubleResolver.php b/src/Resolvers/DoubleResolver.php index 5ef7002..b6d0d35 100644 --- a/src/Resolvers/DoubleResolver.php +++ b/src/Resolvers/DoubleResolver.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; use Cable8mm\Xeed\Types\Bracket; /** @@ -33,4 +34,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Number::make(\''.Inflector::title($this->column->field).'\')->step(\'any\'),'; + } } diff --git a/src/Resolvers/EnumResolver.php b/src/Resolvers/EnumResolver.php index 371081c..358b74e 100644 --- a/src/Resolvers/EnumResolver.php +++ b/src/Resolvers/EnumResolver.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; use Cable8mm\Xeed\Types\Bracket; /** @@ -30,4 +31,11 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + $bracket = Bracket::of($this->column->bracket)->array(); + + return 'Select::make(\''.Inflector::title($this->column->field).'\')->options(['.$bracket.']),'; + } } diff --git a/src/Resolvers/FloatResolver.php b/src/Resolvers/FloatResolver.php index e00e89e..da6d461 100644 --- a/src/Resolvers/FloatResolver.php +++ b/src/Resolvers/FloatResolver.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; use Cable8mm\Xeed\Types\Bracket; /** @@ -41,4 +42,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Number::make(\''.Inflector::title($this->column->field).'\')->step(\'any\'),'; + } } diff --git a/src/Resolvers/GeometryResolver.php b/src/Resolvers/GeometryResolver.php index 0aaa99c..364daeb 100644 --- a/src/Resolvers/GeometryResolver.php +++ b/src/Resolvers/GeometryResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * GEOMETRY */ @@ -19,4 +21,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/IdResolver.php b/src/Resolvers/IdResolver.php index 640a354..d1145a8 100644 --- a/src/Resolvers/IdResolver.php +++ b/src/Resolvers/IdResolver.php @@ -21,4 +21,9 @@ public function migration(): string { return '$table->id();'; } + + public function nova(): ?string + { + return 'ID::make()->sortable(),'; + } } diff --git a/src/Resolvers/InetResolver.php b/src/Resolvers/InetResolver.php index 953dd42..621156d 100644 --- a/src/Resolvers/InetResolver.php +++ b/src/Resolvers/InetResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * INET * @@ -20,4 +22,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/IntResolver.php b/src/Resolvers/IntResolver.php index 042df26..94b218a 100644 --- a/src/Resolvers/IntResolver.php +++ b/src/Resolvers/IntResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * INT(size) * @@ -26,4 +28,15 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + if ($this->column->field === 'id') { + $novaResourceField = 'ID::make()->sortable(),'; + } else { + $novaResourceField = 'Number::make(\''.Inflector::title($this->column->field).'\'),'; + } + + return $novaResourceField; + } } diff --git a/src/Resolvers/JsonResolver.php b/src/Resolvers/JsonResolver.php index 7402aae..df2335a 100644 --- a/src/Resolvers/JsonResolver.php +++ b/src/Resolvers/JsonResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * JSON */ @@ -18,4 +20,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'KeyValue::make(\''.Inflector::title($this->column->field).'\')->rules(\'json\'),'; + } } diff --git a/src/Resolvers/JsonbResolver.php b/src/Resolvers/JsonbResolver.php index 94d87a0..051ddbf 100644 --- a/src/Resolvers/JsonbResolver.php +++ b/src/Resolvers/JsonbResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * JSONB */ @@ -18,4 +20,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'KeyValue::make(\''.Inflector::title($this->column->field).'\')->rules(\'json\'),'; + } } diff --git a/src/Resolvers/LongblobResolver.php b/src/Resolvers/LongblobResolver.php index 07a0ead..25c7030 100644 --- a/src/Resolvers/LongblobResolver.php +++ b/src/Resolvers/LongblobResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * LONGBLOB * @@ -21,4 +23,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Textarea::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/LongtextResolver.php b/src/Resolvers/LongtextResolver.php index 2884ad4..d511ad9 100644 --- a/src/Resolvers/LongtextResolver.php +++ b/src/Resolvers/LongtextResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * LONGTEXT * @@ -20,4 +22,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Textarea::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/MacaddressResolver.php b/src/Resolvers/MacaddressResolver.php index ed84aab..22b8f3e 100644 --- a/src/Resolvers/MacaddressResolver.php +++ b/src/Resolvers/MacaddressResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * MACADDRESS */ @@ -18,4 +20,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/MediumblobResolver.php b/src/Resolvers/MediumblobResolver.php index 76d11b2..3ae773e 100644 --- a/src/Resolvers/MediumblobResolver.php +++ b/src/Resolvers/MediumblobResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * MEDIUMBLOB * @@ -21,4 +23,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Textarea::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/MediumintResolver.php b/src/Resolvers/MediumintResolver.php index f9a6ed6..75ec266 100644 --- a/src/Resolvers/MediumintResolver.php +++ b/src/Resolvers/MediumintResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * MEDIUMINT(size) * @@ -28,4 +30,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Number::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/MediumtextResolver.php b/src/Resolvers/MediumtextResolver.php index f9c9a72..ebd9e82 100644 --- a/src/Resolvers/MediumtextResolver.php +++ b/src/Resolvers/MediumtextResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * MEDIUMTEXT * @@ -20,4 +22,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Textarea::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/MorphsResolver.php b/src/Resolvers/MorphsResolver.php index 5de3768..d26d568 100644 --- a/src/Resolvers/MorphsResolver.php +++ b/src/Resolvers/MorphsResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * MORPHS * @@ -25,4 +27,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Textarea::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/MultipointResolver.php b/src/Resolvers/MultipointResolver.php index e415ee8..f0c4d92 100644 --- a/src/Resolvers/MultipointResolver.php +++ b/src/Resolvers/MultipointResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * MULTIPOINT */ @@ -18,4 +20,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Textarea::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/RemembertokenResolver.php b/src/Resolvers/RemembertokenResolver.php index 60f3ad2..cd1c45f 100644 --- a/src/Resolvers/RemembertokenResolver.php +++ b/src/Resolvers/RemembertokenResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * REMEMBERTOKEN */ @@ -16,4 +18,9 @@ public function migration(): string { return '$table->rememberToken();'; } + + public function nova(): ?string + { + return 'Textarea::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/Resolver.php b/src/Resolvers/Resolver.php index a5a0820..ac7ff3a 100644 --- a/src/Resolvers/Resolver.php +++ b/src/Resolvers/Resolver.php @@ -38,6 +38,15 @@ abstract public function fake(): string; */ abstract public function migration(): string; + /** + * {@inheritDoc} + * + * @internal This method should be implemented by nova resource classes. + * + * @throw LogicException + */ + abstract public function nova(): ?string; + /** * Finally process for resolvers * diff --git a/src/Resolvers/SmallintResolver.php b/src/Resolvers/SmallintResolver.php index f853905..5ac84fa 100644 --- a/src/Resolvers/SmallintResolver.php +++ b/src/Resolvers/SmallintResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * SMALLINT(size) * @@ -26,4 +28,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Number::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/TextResolver.php b/src/Resolvers/TextResolver.php index ecd4eca..18de3db 100644 --- a/src/Resolvers/TextResolver.php +++ b/src/Resolvers/TextResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * TEXT(size) * @@ -20,4 +22,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/TimeResolver.php b/src/Resolvers/TimeResolver.php index 21c924e..20e50d1 100644 --- a/src/Resolvers/TimeResolver.php +++ b/src/Resolvers/TimeResolver.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; use Cable8mm\Xeed\Types\Bracket; /** @@ -27,4 +28,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/TimeTzResolver.php b/src/Resolvers/TimeTzResolver.php index 730bd10..82c58e2 100644 --- a/src/Resolvers/TimeTzResolver.php +++ b/src/Resolvers/TimeTzResolver.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; use Cable8mm\Xeed\Types\Bracket; /** @@ -24,4 +25,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'DateTime::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/TimestampResolver.php b/src/Resolvers/TimestampResolver.php index 5efdb68..2b6753b 100644 --- a/src/Resolvers/TimestampResolver.php +++ b/src/Resolvers/TimestampResolver.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; use Cable8mm\Xeed\Types\Bracket; /** @@ -42,4 +43,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'DateTime::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/TinyblobResolver.php b/src/Resolvers/TinyblobResolver.php index 053f753..f60fae2 100644 --- a/src/Resolvers/TinyblobResolver.php +++ b/src/Resolvers/TinyblobResolver.php @@ -21,4 +21,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return false; + } } diff --git a/src/Resolvers/TinyintResolver.php b/src/Resolvers/TinyintResolver.php index 7faa298..b1c9829 100644 --- a/src/Resolvers/TinyintResolver.php +++ b/src/Resolvers/TinyintResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * TINYINT(size) * @@ -29,4 +31,11 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return $this->column->unsigned ? + 'Number::make(\''.Inflector::title($this->column->field).'\')->min(0)->max(255),' : + 'Number::make(\''.Inflector::title($this->column->field).'\')->min(-128)->max(127),'; + } } diff --git a/src/Resolvers/TinytextResolver.php b/src/Resolvers/TinytextResolver.php index f27ce80..17b496e 100644 --- a/src/Resolvers/TinytextResolver.php +++ b/src/Resolvers/TinytextResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * TINYTEXT * @@ -20,4 +22,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\')->maxlength(255),'; + } } diff --git a/src/Resolvers/UlidResolver.php b/src/Resolvers/UlidResolver.php index 05df0dc..d96500f 100644 --- a/src/Resolvers/UlidResolver.php +++ b/src/Resolvers/UlidResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * ULID */ @@ -22,4 +24,17 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + if (preg_match('/_ulid$/', $this->column->field)) { + $title = Inflector::title(preg_replace('/_ulid$/', '', $this->column->field)); + + $migration = 'BelongsTo::make(\''.$title.'\'),'; + } else { + $migration = 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } + + return $migration; + } } diff --git a/src/Resolvers/UlidmorphsResolver.php b/src/Resolvers/UlidmorphsResolver.php index a22677c..a3ebf3f 100644 --- a/src/Resolvers/UlidmorphsResolver.php +++ b/src/Resolvers/UlidmorphsResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * ULIDMORPHS */ @@ -19,4 +21,12 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + $columnId = Inflector::title($this->column->field).' Id'; + $type = Inflector::title($this->column->field).' Type'; + + return 'Text::make(\''.$columnId.'\'),'.PHP_EOL.'Text::make(\''.$type.'\'),'; + } } diff --git a/src/Resolvers/UuidResolver.php b/src/Resolvers/UuidResolver.php index 0cadc34..1bb3a3b 100644 --- a/src/Resolvers/UuidResolver.php +++ b/src/Resolvers/UuidResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * UUID */ @@ -22,4 +24,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\'),'; + } } diff --git a/src/Resolvers/UuidmorphsResolver.php b/src/Resolvers/UuidmorphsResolver.php index 8baa3bd..36c7ccd 100644 --- a/src/Resolvers/UuidmorphsResolver.php +++ b/src/Resolvers/UuidmorphsResolver.php @@ -19,4 +19,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return false; + } } diff --git a/src/Resolvers/VarbinaryResolver.php b/src/Resolvers/VarbinaryResolver.php index 09460b5..3748029 100644 --- a/src/Resolvers/VarbinaryResolver.php +++ b/src/Resolvers/VarbinaryResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * VARBINARY(size) * @@ -21,4 +23,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\')->maxlength('.$this->column->bracket.'),'; + } } diff --git a/src/Resolvers/VarcharResolver.php b/src/Resolvers/VarcharResolver.php index 91596d5..967a587 100644 --- a/src/Resolvers/VarcharResolver.php +++ b/src/Resolvers/VarcharResolver.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; use Cable8mm\Xeed\Types\Bracket; /** @@ -27,4 +28,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Text::make(\''.Inflector::title($this->column->field).'\')->maxlength(65535),'; + } } diff --git a/src/Resolvers/YearResolver.php b/src/Resolvers/YearResolver.php index 141dc4c..0bce818 100644 --- a/src/Resolvers/YearResolver.php +++ b/src/Resolvers/YearResolver.php @@ -2,6 +2,8 @@ namespace Cable8mm\Xeed\Resolvers; +use Cable8mm\Xeed\Support\Inflector; + /** * YEAR * @@ -22,4 +24,9 @@ public function migration(): string return $this->last($migration); } + + public function nova(): ?string + { + return 'Number::make(\''.Inflector::title($this->column->field).'\')->min(1901)->max(2155),'; + } } diff --git a/src/Support/Inflector.php b/src/Support/Inflector.php index c1621e9..4407e5f 100644 --- a/src/Support/Inflector.php +++ b/src/Support/Inflector.php @@ -17,6 +17,7 @@ final class Inflector /** * Get Class name as Laravel style. + * Returns a word in singular form. * * @param string $string raw table name * @return string The method returns Model class name as Laravel style @@ -32,6 +33,7 @@ public static function classify(string $string): string /** * Get Class name as hasMany method name. + * Returns a word in plural form. * * @param string $string raw Class name * @return string The method returns hasMany method name @@ -47,6 +49,7 @@ public static function pluralize(string $string): string /** * Get Class name as belongsTo method name. + * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'. * * @param string $string raw Class name * @return string The method returns belongsTo method name @@ -59,4 +62,21 @@ public static function tableize(string $string): string return self::$inflector->tableize($string); } + + /** + * get title from Doctrine table + * + * @param string $string raw Class name + * @return string The method returns title + */ + public static function title(string $string): string + { + if (self::$inflector === null) { + self::$inflector = InflectorFactory::create()->build(); + } + + $string = str_replace('_', ' ', $string); + + return ucwords(preg_replace('/\-_/', ' ', self::$inflector->tableize($string))); + } } diff --git a/src/Support/Path.php b/src/Support/Path.php index 31aa7c9..117a9d2 100644 --- a/src/Support/Path.php +++ b/src/Support/Path.php @@ -31,6 +31,18 @@ public static function model(): string return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Models'); } + /** + * Get `Models` folder path. + * + * @return string The model folder path + * + * @example ./dist/app/Nova/ + */ + public static function nova(): string + { + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Nova'); + } + /** * Get `seeders` folder path. * diff --git a/src/Table.php b/src/Table.php index ee74d57..649358b 100644 --- a/src/Table.php +++ b/src/Table.php @@ -81,6 +81,32 @@ public function model(?string $suffix = null): string return Inflector::classify($this->name).$suffix; } + /** + * Get the Nova resource name from table name. + * + * @return string The method returns the NovaResourceName + * + * @example echo (new Table('users'))->nova(); + * //=> User + */ + public function nova(?string $suffix = null): string + { + return $this->model($suffix); + } + + /** + * Get the title for Nova resource name from table name. + * + * @return string The method returns the title for NovaResource name + * + * @example echo (new Table('users'))->title(); + * //=> User + */ + public function title(?string $suffix = null): string + { + return Inflector::title($this->name).$suffix; + } + /** * Get the factory name from table name. * diff --git a/stubs/NovaResource.stub b/stubs/NovaResource.stub new file mode 100644 index 0000000..e083aad --- /dev/null +++ b/stubs/NovaResource.stub @@ -0,0 +1,84 @@ + + */ + public static $model = \App\Models\{model_class_name}::class; + + /** + * The single value that should be used to represent the resource when being displayed. + * + * @var string + */ + public static $title = '{table_title}'; + + /** + * The columns that should be searched. + * + * @var array + */ + public static $search = [ + 'id', + ]; + + /** + * Get the fields displayed by the resource. + * + * @return array + */ + public function fields(NovaRequest $request) + { + return [ +{nova_fields} + ]; + } + + /** + * Get the cards available for the request. + * + * @return array + */ + public function cards(NovaRequest $request) + { + return []; + } + + /** + * Get the filters available for the resource. + * + * @return array + */ + public function filters(NovaRequest $request) + { + return []; + } + + /** + * Get the lenses available for the resource. + * + * @return array + */ + public function lenses(NovaRequest $request) + { + return []; + } + + /** + * Get the actions available for the resource. + * + * @return array + */ + public function actions(NovaRequest $request) + { + return []; + } +} diff --git a/tests/Unit/Resolvers/BigintResolverTest.php b/tests/Unit/Resolvers/BigintResolverTest.php index b44ab4f..38c528c 100644 --- a/tests/Unit/Resolvers/BigintResolverTest.php +++ b/tests/Unit/Resolvers/BigintResolverTest.php @@ -51,4 +51,19 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->bigInteger(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'id'; + + $resolver = new BigintResolver($this->column); + + $this->assertEquals('ID::make()->sortable(),', $resolver->nova()); + + $this->column->field = 'column_name'; + + $resolver = new BigintResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/BoolResolverTest.php b/tests/Unit/Resolvers/BoolResolverTest.php index 079b2ce..a8b4205 100644 --- a/tests/Unit/Resolvers/BoolResolverTest.php +++ b/tests/Unit/Resolvers/BoolResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->boolean(\'boolean\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'bool_field'; + + $resolver = new BoolResolver($this->column); + + $this->assertEquals('Boolean::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/BooleanResolverTest.php b/tests/Unit/Resolvers/BooleanResolverTest.php index 3473528..0322e2b 100644 --- a/tests/Unit/Resolvers/BooleanResolverTest.php +++ b/tests/Unit/Resolvers/BooleanResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->boolean(\'boolean\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'boolean_field'; + + $resolver = new BooleanResolver($this->column); + + $this->assertEquals('Boolean::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/CharResolverTest.php b/tests/Unit/Resolvers/CharResolverTest.php index 19c95f2..36b9644 100644 --- a/tests/Unit/Resolvers/CharResolverTest.php +++ b/tests/Unit/Resolvers/CharResolverTest.php @@ -61,4 +61,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->char(\'char\');', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'char_field'; + + $resolver = new CharResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/DateResolverTest.php b/tests/Unit/Resolvers/DateResolverTest.php index 33510d5..ef8df76 100644 --- a/tests/Unit/Resolvers/DateResolverTest.php +++ b/tests/Unit/Resolvers/DateResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->date(\'date\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'date_field'; + + $resolver = new DateResolver($this->column); + + $this->assertEquals('Date::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/DatetimeResolverTest.php b/tests/Unit/Resolvers/DatetimeResolverTest.php index 7615449..4a6a40e 100644 --- a/tests/Unit/Resolvers/DatetimeResolverTest.php +++ b/tests/Unit/Resolvers/DatetimeResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->dateTime(\'date_time\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'datetime_field'; + + $resolver = new DatetimeResolver($this->column); + + $this->assertEquals('DateTime::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/DecimalResolverTest.php b/tests/Unit/Resolvers/DecimalResolverTest.php index 7020c68..6203e41 100644 --- a/tests/Unit/Resolvers/DecimalResolverTest.php +++ b/tests/Unit/Resolvers/DecimalResolverTest.php @@ -61,4 +61,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->decimal(\''.$resolver->field.'\', 8, 10);', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'decimal_field'; + + $resolver = new DecimalResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\')->step(\'any\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/DoubleResolverTest.php b/tests/Unit/Resolvers/DoubleResolverTest.php index ed5619a..1c22920 100644 --- a/tests/Unit/Resolvers/DoubleResolverTest.php +++ b/tests/Unit/Resolvers/DoubleResolverTest.php @@ -62,4 +62,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->double(\'double\');', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'double_field'; + + $resolver = new DoubleResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\')->step(\'any\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/FloatResolverTest.php b/tests/Unit/Resolvers/FloatResolverTest.php index a4cbd2b..1f4bdcd 100644 --- a/tests/Unit/Resolvers/FloatResolverTest.php +++ b/tests/Unit/Resolvers/FloatResolverTest.php @@ -61,4 +61,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->float(\'float\', 24, 2);', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'float_field'; + + $resolver = new FloatResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\')->step(\'any\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/IdResolverTest.php b/tests/Unit/Resolvers/IdResolverTest.php index 43f6c8f..7c748cb 100644 --- a/tests/Unit/Resolvers/IdResolverTest.php +++ b/tests/Unit/Resolvers/IdResolverTest.php @@ -49,4 +49,11 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->id();', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $resolver = new IdResolver($this->column); + + $this->assertEquals('ID::make()->sortable(),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/IntResolverTest.php b/tests/Unit/Resolvers/IntResolverTest.php index 3dc885c..27769c4 100644 --- a/tests/Unit/Resolvers/IntResolverTest.php +++ b/tests/Unit/Resolvers/IntResolverTest.php @@ -51,4 +51,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->integer(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'int_field'; + + $resolver = new IntResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/IntegerResolverTest.php b/tests/Unit/Resolvers/IntegerResolverTest.php index 206fcaf..9846416 100644 --- a/tests/Unit/Resolvers/IntegerResolverTest.php +++ b/tests/Unit/Resolvers/IntegerResolverTest.php @@ -51,4 +51,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->integer(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'integer_field'; + + $resolver = new IntegerResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/JsonResolverTest.php b/tests/Unit/Resolvers/JsonResolverTest.php index 6dda6af..f6ff3e6 100644 --- a/tests/Unit/Resolvers/JsonResolverTest.php +++ b/tests/Unit/Resolvers/JsonResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->json(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'json_field'; + + $resolver = new JsonResolver($this->column); + + $this->assertEquals('KeyValue::make(\''.$this->column->title().'\')->rules(\'json\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/LongtextResolverTest.php b/tests/Unit/Resolvers/LongtextResolverTest.php index 7e58925..fa38b92 100644 --- a/tests/Unit/Resolvers/LongtextResolverTest.php +++ b/tests/Unit/Resolvers/LongtextResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->longText(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'longtext_field'; + + $resolver = new LongtextResolver($this->column); + + $this->assertEquals('Textarea::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/MacaddressResolverTest.php b/tests/Unit/Resolvers/MacaddressResolverTest.php index a6aa354..6dd2d9a 100644 --- a/tests/Unit/Resolvers/MacaddressResolverTest.php +++ b/tests/Unit/Resolvers/MacaddressResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->macAddress(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'macaddress_field'; + + $resolver = new MacaddressResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/MediumintResolverTest.php b/tests/Unit/Resolvers/MediumintResolverTest.php index 50a31a7..1ad7909 100644 --- a/tests/Unit/Resolvers/MediumintResolverTest.php +++ b/tests/Unit/Resolvers/MediumintResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->mediumInteger(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'mediumint_field'; + + $resolver = new MediumintResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/MediumtextResolverTest.php b/tests/Unit/Resolvers/MediumtextResolverTest.php index 4cfc68d..cf207c0 100644 --- a/tests/Unit/Resolvers/MediumtextResolverTest.php +++ b/tests/Unit/Resolvers/MediumtextResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->mediumText(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'mediumtext_field'; + + $resolver = new MediumtextResolver($this->column); + + $this->assertEquals('Textarea::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/RemembertokenResolverTest.php b/tests/Unit/Resolvers/RemembertokenResolverTest.php index 6d1ef67..ccad9c3 100644 --- a/tests/Unit/Resolvers/RemembertokenResolverTest.php +++ b/tests/Unit/Resolvers/RemembertokenResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->rememberToken();', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'remembertoken_field'; + + $resolver = new RemembertokenResolver($this->column); + + $this->assertEquals('Textarea::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/SmallintResolverTest.php b/tests/Unit/Resolvers/SmallintResolverTest.php index b37dade..c326178 100644 --- a/tests/Unit/Resolvers/SmallintResolverTest.php +++ b/tests/Unit/Resolvers/SmallintResolverTest.php @@ -51,4 +51,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->smallInteger(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'smallint_field'; + + $resolver = new SmallintResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/StringResolverTest.php b/tests/Unit/Resolvers/StringResolverTest.php index 4ba3b2c..8e78f08 100644 --- a/tests/Unit/Resolvers/StringResolverTest.php +++ b/tests/Unit/Resolvers/StringResolverTest.php @@ -61,4 +61,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->string(\''.$resolver->field.'\');', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'string_field'; + + $resolver = new StringResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\')->maxlength(65535),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/TextResolverTest.php b/tests/Unit/Resolvers/TextResolverTest.php index d20ceef..3f7edfc 100644 --- a/tests/Unit/Resolvers/TextResolverTest.php +++ b/tests/Unit/Resolvers/TextResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->text(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'text_field'; + + $resolver = new TextResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/TimeResolverTest.php b/tests/Unit/Resolvers/TimeResolverTest.php index da1a06a..683d57c 100644 --- a/tests/Unit/Resolvers/TimeResolverTest.php +++ b/tests/Unit/Resolvers/TimeResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->time(\''.$resolver->field.'\', 0);', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'time_field'; + + $resolver = new TimeResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/TimestampResolverTest.php b/tests/Unit/Resolvers/TimestampResolverTest.php index 9948f16..b2ed659 100644 --- a/tests/Unit/Resolvers/TimestampResolverTest.php +++ b/tests/Unit/Resolvers/TimestampResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->timestamp(\''.$resolver->field.'\', 0);', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'timestamp_field'; + + $resolver = new TimestampResolver($this->column); + + $this->assertEquals('DateTime::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/TinyintResolverTest.php b/tests/Unit/Resolvers/TinyintResolverTest.php index bf80db5..fc068a2 100644 --- a/tests/Unit/Resolvers/TinyintResolverTest.php +++ b/tests/Unit/Resolvers/TinyintResolverTest.php @@ -51,4 +51,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->tinyInteger(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'tinyint_field'; + + $resolver = new TinyintResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\')->min(-128)->max(127),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/TinytextResolverTest.php b/tests/Unit/Resolvers/TinytextResolverTest.php index 9a04a43..8c86275 100644 --- a/tests/Unit/Resolvers/TinytextResolverTest.php +++ b/tests/Unit/Resolvers/TinytextResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->tinyText(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'tinytext_field'; + + $resolver = new TinytextResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\')->maxlength(255),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/UlidResolverTest.php b/tests/Unit/Resolvers/UlidResolverTest.php index 80de5e5..f426662 100644 --- a/tests/Unit/Resolvers/UlidResolverTest.php +++ b/tests/Unit/Resolvers/UlidResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->ulid(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'ulid_field'; + + $resolver = new UlidResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/UnsignedBigIntegerResolverTest.php b/tests/Unit/Resolvers/UnsignedBigIntegerResolverTest.php index f69cd59..a39c396 100644 --- a/tests/Unit/Resolvers/UnsignedBigIntegerResolverTest.php +++ b/tests/Unit/Resolvers/UnsignedBigIntegerResolverTest.php @@ -61,4 +61,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->bigInteger(\''.$resolver->field.'\');', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'bigint_field'; + + $resolver = new BigintResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/UnsignedIntegerResolverTest.php b/tests/Unit/Resolvers/UnsignedIntegerResolverTest.php index 3aa4cf5..064da42 100644 --- a/tests/Unit/Resolvers/UnsignedIntegerResolverTest.php +++ b/tests/Unit/Resolvers/UnsignedIntegerResolverTest.php @@ -51,4 +51,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->integer(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'int_field'; + + $resolver = new IntResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/UnsignedMediumIntegerResolverTest.php b/tests/Unit/Resolvers/UnsignedMediumIntegerResolverTest.php index 9df3d90..b7e9b67 100644 --- a/tests/Unit/Resolvers/UnsignedMediumIntegerResolverTest.php +++ b/tests/Unit/Resolvers/UnsignedMediumIntegerResolverTest.php @@ -51,4 +51,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->bigInteger(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'bigint_field'; + + $resolver = new BigintResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/UnsignedSmallIntegerResolverTest.php b/tests/Unit/Resolvers/UnsignedSmallIntegerResolverTest.php index a705d64..3d1370a 100644 --- a/tests/Unit/Resolvers/UnsignedSmallIntegerResolverTest.php +++ b/tests/Unit/Resolvers/UnsignedSmallIntegerResolverTest.php @@ -61,4 +61,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->smallInteger(\''.$resolver->field.'\');', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'smallint_field'; + + $resolver = new SmallintResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/UnsignedTinyIntegerResolverTest.php b/tests/Unit/Resolvers/UnsignedTinyIntegerResolverTest.php index 989b61d..129df0c 100644 --- a/tests/Unit/Resolvers/UnsignedTinyIntegerResolverTest.php +++ b/tests/Unit/Resolvers/UnsignedTinyIntegerResolverTest.php @@ -61,4 +61,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->tinyInteger(\''.$resolver->field.'\');', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'tinyint_field'; + + $resolver = new TinyintResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\')->min(-128)->max(127),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/UuidResolverTest.php b/tests/Unit/Resolvers/UuidResolverTest.php index 3178a9f..e1403f9 100644 --- a/tests/Unit/Resolvers/UuidResolverTest.php +++ b/tests/Unit/Resolvers/UuidResolverTest.php @@ -47,4 +47,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->uuid(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'uuid_field'; + + $resolver = new UuidResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\'),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/VarcharResolverTest.php b/tests/Unit/Resolvers/VarcharResolverTest.php index 4f457ec..2de7eb3 100644 --- a/tests/Unit/Resolvers/VarcharResolverTest.php +++ b/tests/Unit/Resolvers/VarcharResolverTest.php @@ -61,4 +61,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->string(\'string\');', $resolver->migration()); } } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'varchar_field'; + + $resolver = new VarcharResolver($this->column); + + $this->assertEquals('Text::make(\''.$this->column->title().'\')->maxlength(65535),', $resolver->nova()); + } } diff --git a/tests/Unit/Resolvers/YearResolverTest.php b/tests/Unit/Resolvers/YearResolverTest.php index 6574f32..c101d4f 100644 --- a/tests/Unit/Resolvers/YearResolverTest.php +++ b/tests/Unit/Resolvers/YearResolverTest.php @@ -51,4 +51,13 @@ public function test_migration_method_can_working_well(): void $this->assertEquals('$table->year(\''.$resolver->field.'\');', $resolver->migration()); } + + public function test_nova_method_can_working_well(): void + { + $this->column->field = 'year_field'; + + $resolver = new YearResolver($this->column); + + $this->assertEquals('Number::make(\''.$this->column->title().'\')->min(1901)->max(2155),', $resolver->nova()); + } }