Skip to content

Commit

Permalink
Fix singleton capsules.
Browse files Browse the repository at this point in the history
  • Loading branch information
haringsrob committed Feb 18, 2022
1 parent 0ce16af commit facb524
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Commands/ModuleMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ public function createCapsuleRoutes(): void

$contents = str_replace(
'{{moduleName}}',
$this->capsule->getModule(),
$this->isSingleton ? lcfirst($this->capsule->getSingular()) : $this->capsule->getModule(),
$this->files->get(__DIR__ . '/stubs/' . $stubFile)
);

Expand Down Expand Up @@ -829,14 +829,14 @@ private function createCapsuleSingletonSeeder(): void {
$repositoryName = $this->capsule->getSingular() . 'Repository';
$seederName = $this->capsule->getSingular() . 'Seeder';

$dir = $this->databasePath('seeders');
$dir = $this->capsule->getSeedsPsr4Path();

$this->makeTwillDirectory($dir);

$stub = $this->files->get(__DIR__ . '/stubs/database_seeder_singleton.stub');

$stub = $this->replaceVariables([
'seederNamespace' => $this->capsule->getDatabaseNamespace() . '\\Seeders',
'seederNamespace' => $this->capsule->getDatabaseNamespace() . '\\Seeds',
'seederClassName' => $seederName,
'modelClass' => $this->capsule->getModelNamespace() . "\\$modelName",
'modelClassName' => $modelName,
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/Capsule.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ public function registerConfig(): void
{
$config = Config::get('twill-navigation', []);

$config[$this->name] = [
$config[lcfirst($this->getSingular())] = [
'title' => $this->name,
'module' => true,
'singleton' => true,
];

Config::set('twill-navigation', $config);
Expand Down
7 changes: 6 additions & 1 deletion src/Http/Controllers/Admin/SingletonModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace A17\Twill\Http\Controllers\Admin;

use A17\Twill\Facades\TwillCapsules;
use Illuminate\Support\Facades\Session;

abstract class SingletonModuleController extends ModuleController
Expand All @@ -17,6 +18,10 @@ public function editSingleton()
{
$model = "App\\Models\\{$this->getModelName()}";

if (!class_exists($model)) {
$model = TwillCapsules::getCapsuleForModel($this->modelName)->getModel();
}

$item = app($model)->first();

if (!$item) {
Expand All @@ -25,6 +30,6 @@ public function editSingleton()

Session::put('pages_back_link', url()->current());

return view("admin.{$this->moduleName}.form", $this->form($item->id));
return view($this->viewPrefix . ".form", $this->form($item->id));
}
}

0 comments on commit facb524

Please sign in to comment.