Skip to content

Commit

Permalink
fix wirecrud id detection
Browse files Browse the repository at this point in the history
  • Loading branch information
manusiakemos committed May 13, 2024
1 parent 68c93cf commit b6c6f77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ composer require manusiakemos/wirecrud

## Usage

```php
// Usage description here
```bash
php artisan wirecrud:make
```

### Testing
Expand Down
6 changes: 3 additions & 3 deletions src/Console/WireCrudConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function handle(): bool
$labelColumn = false;
$type = Schema::getColumnType($tableName, $column);
$keyType = false;
if (Str::contains(haystack: $column, needles: '_id') || Str::contains(haystack: $column, needles: '_by')) {
if (Str::contains(haystack: $column, needles: 'id')) {
$keyType = select(
label: 'choose ' . $column . ' key type',
options: ['primary', 'foreign', 'false'],
Expand All @@ -131,8 +131,8 @@ public function handle(): bool
}

if (!Str::contains(haystack: $column, needles: '_at')) {
if (Str::contains(haystack: $column, needles: '_id') && $keyType == 'foreign') {
$label = Str::replace(search: '_id', replace: '', subject: $column);
if (Str::contains(haystack: $column, needles: 'id') || Str::contains(haystack: $column, needles: '_by') && $keyType == 'foreign') {
$label = Str::replace(search: 'id', replace: '', subject: $column);
} else {
$label = Str::title(Str::snake($column, ' '));
}
Expand Down

0 comments on commit b6c6f77

Please sign in to comment.