Skip to content

Commit

Permalink
Refactor view files
Browse files Browse the repository at this point in the history
  • Loading branch information
sohelamin committed Mar 13, 2024
1 parent 43aa539 commit 4097455
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^5.7|^8.0|^9.0",
"orchestra/testbench": "^3.3|^4.0|^5.0",
"laravel/breeze": "^1.10"
"laravel/breeze": "^1.10|^2.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/CrudApiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ public function handle()

$softDeletes = $this->option('soft-deletes');

$this->call('crud:api-controller', ['name' => $controllerNamespace . $name . 'Controller', '--crud-name' => $name, '--model-name' => $modelName, '--model-namespace' => $modelNamespace, '--pagination' => $perPage, '--validations' => $validations]);
$this->call('crud:api-controller', ['name' => $controllerNamespace . $modelName . 'Controller', '--crud-name' => $name, '--model-name' => $modelName, '--model-namespace' => $modelNamespace, '--pagination' => $perPage, '--validations' => $validations]);
$this->call('crud:model', ['name' => $modelNamespace . $modelName, '--fillable' => $fillable, '--table' => $tableName, '--pk' => $primaryKey, '--relationships' => $relationships, '--soft-deletes' => $softDeletes]);
$this->call('crud:migration', ['name' => $migrationName, '--schema' => $migrationFields, '--pk' => $primaryKey, '--indexes' => $indexes, '--foreign-keys' => $foreignKeys, '--soft-deletes' => $softDeletes]);

// Updating the Http/routes.php file
$routeFile = base_path('routes/api.php');

if (file_exists($routeFile) && (strtolower($this->option('route')) === 'yes')) {
$this->controller = ($controllerNamespace != '') ? $controllerNamespace . $name . 'Controller' : $name . 'Controller';
$this->controller = ($controllerNamespace != '') ? $controllerNamespace . $modelName . 'Controller' : $modelName . 'Controller';

$isAdded = File::append($routeFile, "\n" . implode("\n", $this->addRoutes()));

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/CrudCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function handle()
$formHelper = $this->option('form-helper');
$softDeletes = $this->option('soft-deletes');

$this->call('crud:controller', ['name' => $controllerNamespace . $name . 'Controller', '--crud-name' => $name, '--model-name' => $modelName, '--model-namespace' => $modelNamespace, '--view-path' => $viewPath, '--route-group' => $routeGroup, '--pagination' => $perPage, '--fields' => $fields, '--validations' => $validations]);
$this->call('crud:controller', ['name' => $controllerNamespace . $modelName . 'Controller', '--crud-name' => $name, '--model-name' => $modelName, '--model-namespace' => $modelNamespace, '--view-path' => $viewPath, '--route-group' => $routeGroup, '--pagination' => $perPage, '--fields' => $fields, '--validations' => $validations]);
$this->call('crud:model', ['name' => $modelNamespace . $modelName, '--fillable' => $fillable, '--table' => $tableName, '--pk' => $primaryKey, '--relationships' => $relationships, '--soft-deletes' => $softDeletes]);
$this->call('crud:migration', ['name' => $migrationName, '--schema' => $migrationFields, '--pk' => $primaryKey, '--indexes' => $indexes, '--foreign-keys' => $foreignKeys, '--soft-deletes' => $softDeletes]);
$this->call('crud:view', ['name' => $name, '--fields' => $fields, '--validations' => $validations, '--view-path' => $viewPath, '--route-group' => $routeGroup, '--localize' => $localize, '--pk' => $primaryKey, '--form-helper' => $formHelper]);
Expand All @@ -137,7 +137,7 @@ public function handle()
$routeFile = base_path('routes/web.php');

if (file_exists($routeFile) && (strtolower($this->option('route')) === 'yes')) {
$this->controller = ($controllerNamespace != '') ? $controllerNamespace . $name . 'Controller' : $name . 'Controller';
$this->controller = ($controllerNamespace != '') ? $controllerNamespace . $modelName . 'Controller' : $modelName . 'Controller';

$isAdded = File::append($routeFile, "\n" . implode("\n", $this->addRoutes()));

Expand Down
4 changes: 2 additions & 2 deletions src/stubs/views/blade/create.blade.stub
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Create %%modelName%%
</h2>
<div class="flex justify-end mt-5">
<a class="px-2 py-1 rounded-md bg-sky-500 text-sky-100 hover:bg-sky-600" href="{{ url('/%%routeGroup%%%%viewName%%') }}" title="Back">< Back</a>
<a class="px-2 py-1 rounded-md bg-sky-500 text-sky-100 hover:bg-sky-600" href="{{ route('%%crudName%%.index') }}" title="Back">< Back</a>
</div>
</header>

Expand All @@ -28,7 +28,7 @@
</ul>
@endif

<form method="POST" action="{{ url('/%%routeGroup%%%%viewName%%') }}" class="mt-6 space-y-6" accept-charset="UTF-8" enctype="multipart/form-data">
<form method="POST" action="{{ route('%%crudName%%.store') }}" class="mt-6 space-y-6" accept-charset="UTF-8" enctype="multipart/form-data">
@csrf()
@include ('%%viewTemplateDir%%.form', ['formMode' => 'create'])
</form>
Expand Down
4 changes: 2 additions & 2 deletions src/stubs/views/blade/edit.blade.stub
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Edit %%modelName%% #{{ $%%crudNameSingular%%->%%primaryKey%% }}
</h2>
<div class="flex justify-end mt-5">
<a class="px-2 py-1 rounded-md bg-sky-500 text-sky-100 hover:bg-sky-600" href="{{ url('/%%routeGroup%%%%viewName%%') }}" title="Back">< Back</a>
<a class="px-2 py-1 rounded-md bg-sky-500 text-sky-100 hover:bg-sky-600" href="{{ route('%%crudName%%.index') }}" title="Back">< Back</a>
</div>
</header>

Expand All @@ -28,7 +28,7 @@
</ul>
@endif

<form method="POST" action="{{ url('/%%routeGroup%%%%viewName%%/' . $%%crudNameSingular%%->%%primaryKey%%) }}" class="mt-6 space-y-6" accept-charset="UTF-8" enctype="multipart/form-data">
<form method="POST" action="{{ route('%%crudName%%.update', $%%crudNameSingular%%->%%primaryKey%%) }}" class="mt-6 space-y-6" accept-charset="UTF-8" enctype="multipart/form-data">
{{ method_field('PATCH') }}
@csrf()

Expand Down
17 changes: 11 additions & 6 deletions src/stubs/views/blade/index.blade.stub
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
%%crudNameCap%%
</h2>
<div class="flex justify-end mt-5">
<a href="{{ url('/%%routeGroup%%%%viewName%%/create') }}" class="px-2 py-1 rounded-md bg-sky-500 text-white hover:bg-sky-600" title="Add New %%modelName%%">Add New</a>
<a href="{{ route('%%crudName%%.create') }}" class="px-2 py-1 rounded-md bg-sky-500 text-white hover:bg-sky-600" title="Add New %%modelName%%">Add New</a>
</div>
</header>
</br>

@if (session()->has('flash_message'))
<div class="p-3 rounded bg-green-500 text-green-100 my-2">
{{ session('flash_message') }}
<div class="text-white px-6 py-4 border-0 rounded relative mb-4 bg-emerald-500">
<span class="inline-block align-middle mr-8">
{{ session('flash_message') }}
</span>
<button class="absolute bg-transparent text-2xl font-semibold leading-none right-0 top-0 mt-4 mr-6 outline-none focus:outline-none" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">
<span>×</span>
</button>
</div>
@endif

Expand All @@ -40,10 +45,10 @@
<td class="px-6 py-4">{{ $loop->iteration }}</td>
%%formBodyHtml%%
<td class="px-6 py-4">
<a href="{{ url('/%%routeGroup%%%%viewName%%/' . $item->%%primaryKey%%) }}" title="View %%modelName%%"><button type="button" class="bg-indigo-600 hover:bg-indigo-800 text-white font-bold py-1 px-2 rounded">View</button></a>
<a href="{{ url('/%%routeGroup%%%%viewName%%/' . $item->%%primaryKey%% . '/edit') }}" title="Edit %%modelName%%"><button type="button" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded">Edit</button></a>
<a href="{{ route('%%crudName%%.show', $item->%%primaryKey%%) }}" title="View %%modelName%%"><button type="button" class="bg-indigo-600 hover:bg-indigo-800 text-white font-bold py-1 px-2 rounded">View</button></a>
<a href="{{ route('%%crudName%%.edit', $item->%%primaryKey%%) }}" title="Edit %%modelName%%"><button type="button" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded">Edit</button></a>

<form method="POST" action="{{ url('/%%routeGroup%%%%viewName%%' . '/' . $item->%%primaryKey%%) }}" accept-charset="UTF-8" style="display:inline">
<form method="POST" action="{{ route('%%crudName%%.destroy', $item->%%primaryKey%%) }}" accept-charset="UTF-8" style="display:inline">
{{ method_field('DELETE') }}
@csrf()
<button type="submit" class="bg-red-500 hover:bg-red-700 text-white font-bold py-1 px-2 rounded" title="Delete %%modelName%%" onclick="return confirm(&quot;Confirm delete?&quot;)">Delete</button>
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/views/blade/show.blade.stub
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Show %%modelName%%
</h2>
<div class="flex justify-end mt-5">
<a class="px-2 py-1 rounded-md bg-sky-500 text-sky-100 hover:bg-sky-600" href="{{ url('/%%routeGroup%%%%viewName%%') }}" title="Back">< Back</a>
<a class="px-2 py-1 rounded-md bg-sky-500 text-sky-100 hover:bg-sky-600" href="{{ route('%%crudName%%.index') }}" title="Back">< Back</a>
</div>
</header>
</br>
Expand Down

0 comments on commit 4097455

Please sign in to comment.