CrestApps / laravel-code-generator

An efficient Laravel code generator, saving time by automating the creation of resources such as views, controllers, routes, migrations, languages, and form-requests. Highly flexible and customizable, it includes a cross-browser compatible template and client-side validation for application modernization.
https://laravel-code-generator.crestapps.com
MIT License
738 stars 158 forks source link

error #97

Closed SV-RAJA closed 5 years ago

SV-RAJA commented 5 years ago

F:\nidhi - Login Email HtmlCollective CodeGenerator>php artisan create:resources AssetCategory --with-migration Scaffolding resources for asset category... A model was crafted successfully.

ErrorException : compact(): Undefined variable: viewName

at F:\nidhi - Login Email HtmlCollective CodeGenerator\vendor\crestapps\laravel-code-generator\src\Commands\CreateControllerCommand.php:398 394| 'template', 395| 'controllerName', 396| 'extends', 397| 'withAuth',

398| 'controllerDirectory' 399| ); 400| } 401| 402| /**

Exception trace:

1 compact("formRequestDirectory", "viewDirectory", "viewName", "modelName", "prefix", "perPage", "fileSnippet", "modelDirectory", "langFile", "fields", "withFormRequest", "formRequestName", "force", "resourceFile", "template", "controllerName", "extends", "withAuth", "controllerDirectory") F:\nidhi - Login Email HtmlCollective CodeGenerator\vendor\crestapps\laravel-code-generator\src\Commands\CreateControllerCommand.php:398

MikeAlhayek commented 5 years ago

What version of the package are you using? Also what version of Laravel are you running? Finally, what fields are you using?

SV-RAJA commented 5 years ago

crestapp 2.2 in laravel 5.7

MikeAlhayek commented 5 years ago

What about the fields so I can attempt to reproduce the error

SV-RAJA commented 5 years ago

php artisan resource-file:create AssetCategory --fields=id,name,description,is_active

SV-RAJA commented 5 years ago

What's my error?

HAFVL007 commented 5 years ago

Hi I am having the same issue! Using CreatApps 2.2/Laravel 5.7. I have logged logged issue #102... sorry for the duplication!

Is there a solution to this problem? Thanks

limonazzo commented 5 years ago

I run the command in php7.3 and fails , downgrade to php7.2 works fine. I do not know why. :|

chrishubert commented 5 years ago

Before PHP 7.3, any strings that are not set will silently be skipped. function compact

Run the following function to force php 7.2 version: php7.2 artisan create:resources ...

mvd81 commented 5 years ago

@limonazzo because PHP 7.3 now reports missing variables in the compact function.

If you view the code (vendor/crestapps/laravel-code-generator/src/Commands/CreateControllerCommand.php, method getCommandInput) $viewName, $fileSnippet and $fields are not defined. For now i comment out these variables to prevent errors in PHP7.3

protected function getCommandInput()
    {
        $modelName = trim($this->argument('model-name'));
        $cName = trim($this->option('controller-name'));
        $controllerName = $cName ? str_finish($cName, Config::getControllerNamePostFix()) : Helpers::makeControllerName($modelName);
        $viewDirectory = $this->option('views-directory');
        $prefix = ($this->option('routes-prefix') == 'default-form') ? Helpers::makeRouteGroup($modelName) : $this->option('routes-prefix');
        $perPage = intval($this->option('models-per-page'));
        $resourceFile = trim($this->option('resource-file')) ?: Helpers::makeJsonFileName($modelName);
        $langFile = $this->option('language-filename') ?: Helpers::makeLocaleGroup($modelName);
        $withFormRequest = $this->option('with-form-request');
        $force = $this->option('force');
        $modelDirectory = $this->option('model-directory');
        $controllerDirectory = trim($this->option('controller-directory'));
        $formRequestName = Helpers::makeFormRequestName($modelName);
        $template = $this->getTemplateName();
        $formRequestDirectory = trim($this->option('form-request-directory'));
        $extends = $this->generatorOption('controller-extends');
        $withAuth = $this->option('with-auth');

        return (object) compact(
            'formRequestDirectory',
            'viewDirectory',
            //'viewName',
            'modelName',
            'prefix',
            'perPage',
            //'fileSnippet',
            'modelDirectory',
            'langFile',
            //'fields',
            'withFormRequest',
            'formRequestName',
            'force',
            'resourceFile',
            'template',
            'controllerName',
            'extends',
            'withAuth',
            'controllerDirectory'
        );
    }
MikeAlhayek commented 5 years ago

Thank you for reporting this issue! This issue has been addressed and now part of the v2.2.13 release. Please upgrade your package to fix the issue