diff --git a/resources/views/_helper_form.blade.php b/resources/views/_helper_form.blade.php
index 21944d1..147ad35 100644
--- a/resources/views/_helper_form.blade.php
+++ b/resources/views/_helper_form.blade.php
@@ -1,81 +1,80 @@
@foreach ($fields as $field)
@switch($field['type'])
+ @case('boolean')
+
+ @break
@case('file')
-
@break
@case('date')
-
@break
@case('datetime')
-
@break
-
@case('time')
-
+
@break
@case('longtext')
-
+
@break
@case('select')
-
+
@break
@case('string')
-
+
@break
@case('text')
-
+
@break
@case('integer')
-
+
@break
@case('double' || 'float')
-
+
@break
@case('radio')
-
@break
@case('tinyint')
-
- @break
- @case('boolean')
-
+
@break
@endswitch
@endforeach
diff --git a/src/Console/WireCrudConsole.php b/src/Console/WireCrudConsole.php
index 329f821..f0a7e88 100644
--- a/src/Console/WireCrudConsole.php
+++ b/src/Console/WireCrudConsole.php
@@ -27,7 +27,7 @@ class WireCrudConsole extends Command
protected string $className;
- protected string $classNameLower;
+ protected string $classNameCamel;
protected string $classNameSpace;
@@ -53,9 +53,9 @@ public function handle(): bool
{
//ask to use uuid
$this->uuid = select(
- label:'ID is uuid',
- options:['yes', 'no'],
- default:config('wirecrud.uuid') ? 'yes' : 'no',
+ label: 'ID is uuid',
+ options: ['yes', 'no'],
+ default: config('wirecrud.uuid') ? 'yes' : 'no',
);
$tableName = text(label: 'table name on database:', required: true);
$columns = Schema::getColumnListing($tableName);
@@ -64,7 +64,7 @@ public function handle(): bool
return false;
}
- $className = text(label: 'class name:', default: Str::ucfirst($tableName), required: true);
+ $className = text(label: 'class name:', default: Str::studly($tableName), required: true);
$pageType = select(
label: 'Form Type',
options: ['modal', 'page'],
@@ -141,7 +141,7 @@ public function handle(): bool
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::replace('_', ' ',Str::snake($column, ' '));
+ $label = Str::replace('_', ' ', Str::snake($column, ' '));
}
$fields->push([
@@ -158,9 +158,9 @@ public function handle(): bool
Log::debug('fields', $fields->toArray());
$this->fields = $fields;
$this->className = $className;
- $this->classNameLower = strtolower(Str::camel($className));
- $this->classNameSlug = strtolower(Str::slug(Str::snake($className, '-')));
- $this->classNameSpace = Str::replace('_', ' ', Str::title($className));
+ $this->classNameSpace = Str::of($className)->headline();
+ $this->classNameCamel = Str::of($this->classNameSpace)->camel();
+ $this->classNameSlug = Str::of($this->classNameSpace)->slug();
$this->table = $tableName;
$this->isModal = $pageType == 'modal';
$this->hasUpload = $hasUpload;
@@ -310,16 +310,16 @@ private function generateLivewire(): void
$useTraitFile = View::make('wirecrud::_use-trait')->render();
$traitFile = 'use UploadFileTrait,WithFileUploads;';
$storeUpload = View::make('wirecrud::_store-upload', [
- 'classNameLower' => $this->classNameLower,
+ 'classNameLower' => $this->classNameCamel,
'uploadColumn' => $this->fields->where('type', '=', 'file')->first(),
])->render();
$updateUpload = View::make('wirecrud::_update-upload', [
- 'classNameLower' => $this->classNameLower,
+ 'classNameLower' => $this->classNameCamel,
'uploadColumn' => $this->fields->where('type', '=', 'file')->first(),
])->render();
$deleteUpload = View::make('wirecrud::_delete-upload', [
- 'classNameLower' => $this->classNameLower,
+ 'classNameLower' => $this->classNameCamel,
'uploadColumn' => $this->fields->where('type', '=', 'file')->first(),
])->render();
} else {
@@ -336,13 +336,13 @@ private function generateLivewire(): void
$handleRequest = View::make('wirecrud::_helper_handle_request', [
'fields' => $this->fields,
- 'classNameLower' => $this->classNameLower,
+ 'classNameLower' => $this->classNameCamel,
])->render();
$validate = View::make('wirecrud::_helper_validate_generator', [
'hasUpload' => $this->hasUpload,
'field_validate' => $this->fields->where('key_type', '<>', 'primary')->where('type', '<>', 'file'),
- 'classNameLower' => $this->classNameLower,
+ 'classNameLower' => $this->classNameCamel,
])->render();
$generatedProps = View::make('wirecrud::_helper_props', [
@@ -351,7 +351,7 @@ private function generateLivewire(): void
$columns = View::make('wirecrud::_helper_columns', [
'fields' => $this->fields->where('key_type', '<>', 'primary'),
- 'classNameLower' => $this->classNameLower,
+ 'classNameLower' => $this->classNameCamel,
])->render();
$stubTemplate = [
@@ -382,7 +382,7 @@ private function generateLivewire(): void
$traitFile,
$this->primaryKey,
$this->className,
- $this->classNameLower,
+ $this->classNameCamel,
$handleRequest,
$validate,
$columns,
@@ -441,7 +441,7 @@ private function generateViewPage(): void
$this->primaryKey,
$this->className,
$this->classNameSlug,
- $this->classNameLower,
+ $this->classNameCamel,
$this->classNameSpace,
];
if ($this->isModal) {
@@ -461,9 +461,9 @@ public function generateFormView(): void
{
$forms = View::make('wirecrud::_helper_form', [
'fields' => $this->fields->where('key_type', '<>', 'primary'),
- 'model' => $this->classNameLower,
+ 'model' => $this->classNameCamel,
])->render();
- $forms = str_replace('xxx', 'x', $forms);
+ $forms = str_replace('wirex', 'x', $forms);
$search = [
'{@pk}',
@@ -480,7 +480,7 @@ public function generateFormView(): void
$this->table,
$forms,
$this->classNameSlug,
- $this->classNameLower,
+ $this->classNameCamel,
$this->classNameSpace,
];
@@ -510,7 +510,7 @@ public function generateActionView(): void
$stubReplaceTemplate = [
$this->primaryKey,
$this->className,
- $this->classNameLower,
+ $this->classNameCamel,
$this->classNameSlug,
];
if ($this->isModal) {
@@ -537,13 +537,13 @@ public function generateNavigationView(): void
$replace = [
$this->primaryKey,
$this->className,
- $this->classNameLower,
+ $this->classNameCamel,
$this->classNameSlug,
$this->classNameSpace,
];
$subject = file_get_contents($this->getStub('nav.stub'));
$template = str_replace($search, $replace, $subject);
- $path = resource_path("views/livewire/$this->classNameLower");
+ $path = resource_path("views/livewire/$this->classNameCamel");
File::isDirectory($path) or File::makeDirectory($path, 0755, true, true);
$pathToWrite = resource_path("views/livewire/$this->classNameSlug/_$this->classNameSlug-nav.blade.php");
file_put_contents($pathToWrite, $template);
@@ -590,7 +590,7 @@ public function generateApi(): void
{
$validate = View::make('wirecrud::_helper_validate_generator_api', [
'field_validate' => $this->fields->where('key_type', '<>', 'primary'),
- 'classNameLower' => $this->classNameLower,
+ 'classNameLower' => $this->classNameCamel,
])->render();
$stubTemplate = [
@@ -601,7 +601,7 @@ public function generateApi(): void
];
$stubReplaceTemplate = [
$this->className,
- $this->classNameLower,
+ $this->classNameCamel,
$this->classNameSlug,
$validate,
];
@@ -623,7 +623,7 @@ public function generateSortable(): void
];
$stubReplaceTemplate = [
$this->className,
- $this->classNameLower,
+ $this->classNameCamel,
$this->classNameSlug,
$this->primaryKey,
];
diff --git a/src/Console/stubs/livewire-modal.stub b/src/Console/stubs/livewire-modal.stub
index 07eeb39..23725f0 100644
--- a/src/Console/stubs/livewire-modal.stub
+++ b/src/Console/stubs/livewire-modal.stub
@@ -6,16 +6,13 @@ use Livewire\Component;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
-use App\Services\{@className}\{@className}Service;
+use App\Repositories\{@className}\{@className}Repository;
use WireUi\Traits\Actions;
-{@useTraitFile}
class {@className}Page extends Component
{
- {@traitFile}
-
protected $listeners = ['create', 'edit'];
- protected {@className}Service ${@classNameLower}Service;
+ protected {@className}Repository ${@classNameLower}Repository;
public mixed $myFile = null;
@@ -25,9 +22,9 @@ class {@className}Page extends Component
public bool $showModalForm = false;
{@options}
- public function boot({@className}Service ${@classNameLower}Service): void
+ public function boot({@className}Repository ${@classNameLower}Repository): void
{
- $this->{@classNameLower}Service = ${@classNameLower}Service;
+ $this->{@classNameLower}Repository = ${@classNameLower}Repository;
}
public function mount(): void
@@ -71,7 +68,7 @@ class {@className}Page extends Component
);
$this->updateMode = false;
{@storeUpload}
- $this->{@classNameLower}Service->create($data['{@classNameLower}']);
+ $this->{@classNameLower}Repository->create($data['{@classNameLower}']);
$this->reset(['{@classNameLower}', 'showModalForm']);
$this->notification()->send([
'title' => '{@classNameSpace} berhasil ditambahkan',
@@ -85,7 +82,7 @@ class {@className}Page extends Component
$this->reset(['{@classNameLower}', 'showModalForm','myFile']);
$this->updateMode = true;
$this->setOptions();
- $this->{@classNameLower} = $this->{@classNameLower}Service->find($id)->toArray();
+ $this->{@classNameLower} = $this->{@classNameLower}Repository->find($id)->toArray();
$this->showModalForm = true;
}
@@ -97,7 +94,7 @@ class {@className}Page extends Component
);
{@updateUpload}
if ($this->{@classNameLower}['{@primaryKey}'] && $this->updateMode) {
- $this->{@classNameLower}Service->update($this->{@classNameLower}['{@primaryKey}'],$data['{@classNameLower}']);
+ $this->{@classNameLower}Repository->update($this->{@classNameLower}['{@primaryKey}'],$data['{@classNameLower}']);
} else {
abort('403', '{@className} Not Found');
}
@@ -111,7 +108,7 @@ class {@className}Page extends Component
public function destroy($id): void
{
- $data = $this->{@classNameLower}Service->find($id);
+ $data = $this->{@classNameLower}Repository->find($id);
{@deleteUpload}
$data->delete();
$this->notification()->send([