# HG changeset patch # User Luka Sitas # Date 1747011831 14400 # Node ID 1a717c7b211f7a90c6605fac0fa1ef1af5d8d131 # Parent 31109c61ce02d4128e8de21192fb5bd8698fced0 added support for some basic views diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/Controller/stubs/controller.stub --- a/src/Generator/Controller/stubs/controller.stub Tue Apr 22 21:37:44 2025 -0400 +++ b/src/Generator/Controller/stubs/controller.stub Sun May 11 21:03:51 2025 -0400 @@ -17,6 +17,7 @@ { $data = []; $data['items'] = {{ model }}::all(); + $data['fields'] = (new {{ model }}()->getFillable()); return view('{{ tableName }}.index', $data); } @@ -29,6 +30,7 @@ public function create() { $data = []; + $data['fields'] = (new {{ model }}()->getFillable()); return view('{{ tableName }}.create_edit', $data); } @@ -58,6 +60,7 @@ { $data = []; $data['item'] = ${{ modelVariable }}; + $data['fields'] = (new {{ model }}()->getFillable()); return view('{{ tableName }}.show', $data); } @@ -72,6 +75,7 @@ { $data = []; $data['item'] = ${{ modelVariable }}; + $data['fields'] = (new {{ model }}()->getFillable()); // Load data for relationships diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/Generator.php --- a/src/Generator/Generator.php Tue Apr 22 21:37:44 2025 -0400 +++ b/src/Generator/Generator.php Sun May 11 21:03:51 2025 -0400 @@ -47,6 +47,7 @@ $this->input->setOption('controller', true); $this->input->setOption('model', true); $this->input->setOption('request', true); + $this->input->setOption('view', true); $this->input->setOption('route', true); } @@ -74,6 +75,10 @@ $this->createRequest(); } + if ($this->option('view')) { + $this->createView(); + } + if ($this->option('route')) { $this->createRoute(); } @@ -89,6 +94,7 @@ ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], ['model', 'm', InputOption::VALUE_NONE, 'Generate a model class for the table.'], ['request', 'r', InputOption::VALUE_NONE, 'Generate base request classes for the table.'], + ['view', '', InputOption::VALUE_NONE, 'Generate base views for the table.'], ['route', 'w', InputOption::VALUE_NONE, 'Generate base routes classes for the table.'], ]); } @@ -115,6 +121,11 @@ $this->call('mf:request', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); } + protected function createView() + { + $this->call('mf:view', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); + } + protected function createRoute() { $this->call('mf:route', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/View/CreateEditViewGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/View/CreateEditViewGenerator.php Sun May 11 21:03:51 2025 -0400 @@ -0,0 +1,77 @@ +resolveStubPath('/stubs/create_edit.stub'); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + protected function getClassName($name) + { + return $this->create_edit_view_name($name); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getPath($name = null) + { + return str_replace(['Resources\\', '\\'], ['resources/', '/'], $this->getViewNamespace($this->getTableInput()).'create_edit.blade.php'); + } +} diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/View/IndexViewGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/View/IndexViewGenerator.php Sun May 11 21:03:51 2025 -0400 @@ -0,0 +1,77 @@ +resolveStubPath('/stubs/index.stub'); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + protected function getClassName($name) + { + return $this->index_view_name($name); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getPath($name = null) + { + return str_replace(['Resources\\', '\\'], ['resources/', '/'], $this->getViewNamespace($this->getTableInput()).'index.blade.php'); + } +} diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/View/ShowViewGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/View/ShowViewGenerator.php Sun May 11 21:03:51 2025 -0400 @@ -0,0 +1,77 @@ +resolveStubPath('/stubs/show.stub'); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + protected function getClassName($name) + { + return $this->show_view_name($name); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getPath($name = null) + { + return str_replace(['Resources\\', '\\'], ['resources/', '/'], $this->getViewNamespace($this->getTableInput()).'show.blade.php'); + } +} diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/View/ViewGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/View/ViewGenerator.php Sun May 11 21:03:51 2025 -0400 @@ -0,0 +1,105 @@ +tableExists($this->getTableInput())) { + $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); + + return false; + } + + if ($this->option('all')) { + $this->input->setOption('index_view', true); + $this->input->setOption('create_edit_view', true); + $this->input->setOption('show_view', true); + } + + if ($this->option('index_view')) { + $this->createIndexView(); + } + + if ($this->option('create_edit_view')) { + $this->createCreateEditView(); + } + + if ($this->option('show_view')) { + $this->createShowView(); + } + } + + /** + * Get the console command options. + */ + protected function getOptions(): array + { + return array_merge(parent::getOptions(), [ + ['all', 'a', InputOption::VALUE_NONE, 'Generate all views for the table.'], + ['index_view', 'i', InputOption::VALUE_NONE, 'Generate index view for the table.'], + ['create_edit_view', 'c', InputOption::VALUE_NONE, 'Generate create_edit view for the table.'], + ['show_view', 's', InputOption::VALUE_NONE, 'Generate show view for the table.'], + ]); + } + + /** + * Interact further with the user if they were prompted for missing arguments. + */ + protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output): void {} + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() {} + + protected function createIndexView() + { + $this->call('mf:index_view', ['table' => $this->getTableInput()]); + } + + protected function createCreateEditView() + { + $this->call('mf:create_edit_view', ['table' => $this->getTableInput()]); + } + + protected function createShowView() + { + $this->call('mf:show_view', ['table' => $this->getTableInput()]); + } +} diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/View/stubs/create_edit.stub --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/View/stubs/create_edit.stub Sun May 11 21:03:51 2025 -0400 @@ -0,0 +1,39 @@ + + +

+ {{ isset($item) ? 'Edit' : 'Create' }} {{ ucfirst('{{ modelVariable }}') }} +

+
+ +
+
+
+
+ @csrf + @if(isset($item)) + @method('PUT') + @endif + + @foreach($fields as $field) +
+ + + @error($field) + {{ $message }} + @enderror +
+ @endforeach + +
+ Back + +
+
+
+
+
+
diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/View/stubs/index.stub --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/View/stubs/index.stub Sun May 11 21:03:51 2025 -0400 @@ -0,0 +1,52 @@ + + +

+ All {{ Str::plural(ucfirst('{{ modelVariable }}')) }} +

+
+ +
+
+
+ + + + + @foreach($fields as $field) + + @endforeach + + + + + @forelse ($items as $item) + + @foreach($fields as $field) + + @endforeach + + + @empty + + + + @endforelse + +
{{ ucfirst($field) }}Actions
{{ $item->$field }} + View + Edit +
+ @csrf + @method('DELETE') + +
+
No {{ tableName }} found.
+
+
+
+
diff -r 31109c61ce02 -r 1a717c7b211f src/Generator/View/stubs/show.stub --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/View/stubs/show.stub Sun May 11 21:03:51 2025 -0400 @@ -0,0 +1,26 @@ + + +

+ {{ ucfirst('{{ modelVariable }}') }} Details +

+
+ +
+
+
+
+ @foreach($fields as $field) +
+ {{ ucfirst($field) }}: + {{ $item->$field }} +
+ @endforeach +
+
+ Edit + Back +
+
+
+
+
diff -r 31109c61ce02 -r 1a717c7b211f src/MagicForgerServiceProvider.php --- a/src/MagicForgerServiceProvider.php Tue Apr 22 21:37:44 2025 -0400 +++ b/src/MagicForgerServiceProvider.php Sun May 11 21:03:51 2025 -0400 @@ -10,6 +10,10 @@ use Wizard\MagicForger\Generator\Requests\StoreRequestGenerator; use Wizard\MagicForger\Generator\Requests\UpdateRequestGenerator; use Wizard\MagicForger\Generator\Route\RouteGenerator; +use Wizard\MagicForger\Generator\View\ViewGenerator; +use Wizard\MagicForger\Generator\View\IndexViewGenerator; +use Wizard\MagicForger\Generator\View\CreateEditViewGenerator; +use Wizard\MagicForger\Generator\View\ShowViewGenerator; class MagicForgerServiceProvider extends ServiceProvider { @@ -27,6 +31,10 @@ StoreRequestGenerator::class, UpdateRequestGenerator::class, RouteGenerator::class, + ViewGenerator::class, + IndexViewGenerator::class, + CreateEditViewGenerator::class, + ShowViewGenerator::class, ]); } diff -r 31109c61ce02 -r 1a717c7b211f src/Replacer/Replacer.php --- a/src/Replacer/Replacer.php Tue Apr 22 21:37:44 2025 -0400 +++ b/src/Replacer/Replacer.php Sun May 11 21:03:51 2025 -0400 @@ -114,6 +114,30 @@ return 'Update'.$this->model_name($name).'Request'; } + + /** + * Generate the index view name. + */ + public function index_view_name(string $name): string + { + return ''; + } + + /** + * Generate the create_edit view name. + */ + public function create_edit_view_name(string $name): string + { + return ''; + } + + /** + * Generate the show view name. + */ + public function show_view_name(string $name): string + { + return ''; + } // Namespace Methods // These methods handle the formation of various namespaces used within the replacements. @@ -174,6 +198,39 @@ } /** + * Get the view namespace. + */ + public function getViewNamespace(string $name): string + { + return $this->viewPath($name) . '\\'; + } + + /** + * Get the index view namespace. + */ + public function getIndexViewNamespace(string $name): string + { + return $this->getViewNamespace($name) . '\\'; + } + + /** + * Get the create_edit view namespace. + */ + public function getCreateEditViewNamespace(string $name): string + { + return $this->getViewNamespace($name) . '\\'; + } + + /** + * Get the show view namespace. + */ + public function getShowViewNamespace(string $name): string + { + return $this->getViewNamespace($name) . '\\'; + } + + + /** * Get the request uses string for replacement. */ public function getRequestUses(string $name): string