Skip to content

Commit

Permalink
add support to uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
manusiakemos committed May 23, 2024
1 parent 60480c1 commit 04dabd4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
'service' => true,
'view' => true,
'api' => true,
'uuid' => true,
];
16 changes: 13 additions & 3 deletions src/Console/WireCrudConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class WireCrudConsole extends Command
{
protected $signature = 'wirecrud:make';

protected $description = 'Generate Livewire 3 CRUD From Tables';
protected $description = 'Generate Livewire 3 CRUD From Existing Tables';

protected bool $uuid;

protected Collection $fields;

Expand Down Expand Up @@ -49,7 +51,12 @@ protected function getStub($filename): string

public function handle(): bool
{
$this->getStub('a');
//ask to use uuid
$this->uuid = select(
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);
if (count($columns) == 0) {
Expand Down Expand Up @@ -163,7 +170,6 @@ public function handle(): bool
if ($generateModel == 'yes') {
$this->generateModel();
}

if ($generateService == 'yes') {
$this->generateService();
$this->generateRepository();
Expand Down Expand Up @@ -209,12 +215,16 @@ private function generateModel(): void
'{@className}',
'{@table}',
'{@primaryKey}',
'{@useUUid}',
'{@uuid}',
];

$stubReplaceTemplate = [
$this->className,
$this->table,
$this->primaryKey,
$this->uuid ? 'use Illuminate\Database\Eloquent\Concerns\HasUuids;' : '',
$this->uuid ? 'use HasUuids;' : '',
];
$stub_template = file_get_contents($this->getStub('model.stub'));
$modelTemplate = str_replace($stubTemplate, $stubReplaceTemplate, $stub_template);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/stubs/action-modal.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="flex justify-center items-center gap-1">
<x-button.circle primary icon="pencil" wire:click="$parent.edit('{{$row->{@primaryKey}}}')"/>
<x-button.circle negative icon="trash" wire:click="$dispatchTo('{@classNameSlug}.{@classNameSlug}-page','confirmDestroy',{ id : {{$row->{@primaryKey}}} })"/>
<x-button.circle negative icon="trash" wire:click="$dispatchTo('{@classNameSlug}.{@classNameSlug}-page','confirmDestroy',{ id : '{{$row->{@primaryKey}}}' })"/>
</div>
2 changes: 1 addition & 1 deletion src/Console/stubs/form-modal.stub
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<x-modal.card blur wire:model.defer="showModalForm" align="start">
<form action="#" wire:submit.prevent="save" class="relative flex flex-col gap-4">

<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="grid grid-cols-1 gap-4">
{@forms}
</div>

Expand Down
4 changes: 4 additions & 0 deletions src/Console/stubs/model.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model;

{@useUUid}

class {@className} extends Model
{

use HasFactory;

{@uuid}

protected $guarded = [];

protected $table = "{@table}";
Expand Down

0 comments on commit 04dabd4

Please sign in to comment.