studly($module); $model = $this->studly($model); $table = str($model)->plural()->snake()->toString(); $route = str($model)->plural()->kebab()->toString(); $root = rtrim(config('developer.modules_path', base_path('Modules')), '/').'/'.$module; $timestamp = now()->format('Y_m_d_His'); $files = [ "$root/Models/{$model}.php" => $this->model($module, $model), "$root/Http/Controllers/{$model}Controller.php" => $this->controller($module, $model), "$root/Http/Requests/Store{$model}Request.php" => $this->request($module, $model), "$root/Database/Migrations/{$timestamp}_create_{$table}_table.php" => $this->migration($table), "$root/Resources/views/admin/{$route}/index.blade.php" => $this->indexView($model, $route), "$root/Resources/views/admin/{$route}/form.blade.php" => $this->formView($model), "$root/Tests/Feature/{$model}CrudTest.php" => $this->crudTest($module, $model), ]; foreach ($files as $path => $contents) { $this->write($path, $contents, $force); } return array_keys($files); } private function model(string $module, string $model): string { return " 'boolean'];\n }\n}\n"; } private function controller(string $module, string $model): string { $plural = str($model)->plural()->kebab(); return "snake()."::admin.{$plural}.index', ['records' => {$model}::query()->latest()->paginate()]);\n }\n\n public function store(Store{$model}Request \$request): RedirectResponse\n {\n {$model}::query()->create(\$request->validated());\n return back()->with('status', '{$model} created.');\n }\n}\n"; } private function request(string $module, string $model): string { return "user() !== null; }\n public function rules(): array { return ['name' => ['required', 'string', 'max:255'], 'is_active' => ['sometimes', 'boolean']]; }\n}\n"; } private function migration(string $table): string { return "id(); \$table->string('name'); \$table->boolean('is_active')->default(true); \$table->timestamps(); }); }\n public function down(): void { Schema::dropIfExists('{$table}'); }\n};\n"; } private function indexView(string $model, string $route): string { return "\n

{$model}

@foreach (\$records as \$record)
{{ \$record->name }}
@endforeach{{ \$records->links() }}
\n
\n"; } private function formView(string $model): string { return "
@csrf{{ __('Save {$model}') }}\n"; } private function crudTest(string $module, string $model): string { return "create(['name' => 'Example']))->toBeInstanceOf({$model}::class); });\n"; } }