InfyOmLabs / laravel-generator

API and Admin Panel CRUD Generator for Laravel.
https://www.infyom.com/open-source
MIT License
3.79k stars 813 forks source link

Generate Scaffold from table fails writing PHPDocType because relations #457

Closed casivaagustin-zz closed 7 years ago

casivaagustin-zz commented 7 years ago

I have this table

CREATE TABLE `devices` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `device` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `imsi` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `imei` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `udid` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pushId` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `os` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `user_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `devices_user_id_foreign` (`user_id`),
  CONSTRAINT `devices_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

That has a relationship to users with the user_id field.

I'm trying to generate the scaffold for that table with this command

artisan infyom:scaffold Device --fromTable --tableName=devices

And I'm getting this error

  [ErrorException]     
  Undefined offset: 1  

Doing a little of research I have this trace

vagrant@local:~/Code/api$ artisan infyom:scaffold Device --fromTable --tableName=devices -vvv

  [ErrorException]     
  Undefined offset: 1  

Exception trace:
 () at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:154
 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:154
 InfyOm\Generator\Generators\ModelGenerator->getPHPDocType() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:129
 InfyOm\Generator\Generators\ModelGenerator->fillDocs() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:68
 InfyOm\Generator\Generators\ModelGenerator->fillTemplate() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:46
 InfyOm\Generator\Generators\ModelGenerator->generate() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Commands/BaseCommand.php:66
 InfyOm\Generator\Commands\BaseCommand->generateCommonItems() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Commands/Scaffold/ScaffoldGeneratorCommand.php:44
 InfyOm\Generator\Commands\Scaffold\ScaffoldGeneratorCommand->handle() at n/a:n/a
 call_user_func_array() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
 Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
 Illuminate\Container\BoundMethod::call() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:539
 Illuminate\Container\Container->call() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:182
 Illuminate\Console\Command->execute() at /home/vagrant/Code/api/vendor/symfony/console/Command/Command.php:264
 Symfony\Component\Console\Command\Command->run() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:167
 Illuminate\Console\Command->run() at /home/vagrant/Code/api/vendor/symfony/console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/Code/api/vendor/symfony/console/Application.php:228
 Symfony\Component\Console\Application->doRun() at /home/vagrant/Code/api/vendor/symfony/console/Application.php:130
 Symfony\Component\Console\Application->run() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:122
 Illuminate\Foundation\Console\Kernel->handle() at /home/vagrant/Code/api/artisan:35

Looking into the getPHPDocType method i see this line

            case 'mt1':
                return camel_case($relation->inputs[1].' '.camel_case($relation->inputs[1]));

Doing a var_dump over relation to see what is having I got this

object(InfyOm\Generator\Common\GeneratorFieldRelation)#1146 (2) {
  ["type"]=>
  string(3) "mt1"
  ["inputs"]=>
  array(1) {
    [0]=>
    string(4) "User"
  }
}

As you can see there is no element 1.

I can not get more information to solve this issue, not sure why is expecting something in the position 1.

Hope the information helps to solve this issue.

Regards

keskin commented 7 years ago

+1

ekohere commented 7 years ago

+1

dhcmega commented 7 years ago

same problem

mitulgolakiya commented 7 years ago

I will be working on this soon and will try to get this out this weekend.

mitulgolakiya commented 7 years ago

@casivaagustin @dhcmega just fixed the issue. Get the latest code and let me know if you face any problem.

dhcmega commented 7 years ago

working. thanks!