GithubHelp home page GithubHelp logo

reliese / laravel Goto Github PK

View Code? Open in Web Editor NEW
1.4K 53.0 304.0 633 KB

Reliese Laravel Model Generator

License: MIT License

PHP 100.00%
laravel scaffold laravel-components database eloquent eloquent-models mysql-database

laravel's Introduction

Reliese Laravel Model Generator

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Reliese Laravel Model Generator aims to speed up the development process of Laravel applications by providing some convenient code-generation capabilities. The tool inspects your database structure, including column names and foreign keys, in order to automatically generate Models that have correctly typed properties, along with any relationships to other Models.

How does it work?

This package expects that you are using Laravel 5.1 or above. You will need to import the reliese/laravel package via composer:

Configuration

It is recommended that this package should only be used on a local environment for security reasons. You should install it via composer using the --dev option like this:

composer require reliese/laravel --dev

Add the models.php configuration file to your config directory and clear the config cache:

php artisan vendor:publish --tag=reliese-models

# Let's refresh our config cache just in case
php artisan config:clear

Models

Generating models with artisan

Usage

Assuming you have already configured your database, you are now all set to go.

  • Let's scaffold some of your models from your default connection.
php artisan code:models
  • You can scaffold a specific table like this:
php artisan code:models --table=users
  • You can also specify the connection:
php artisan code:models --connection=mysql
  • If you are using a MySQL database, you can specify which schema you want to scaffold:
php artisan code:models --schema=shop

Customizing Model Scaffolding

To change the scaffolding behaviour you can make config/models.php configuration file fit your database needs. Check it out ;-)

Tips

1. Keeping model changes

You may want to generate your models as often as you change your database. In order not to lose your own model changes, you should set base_files to true in your config/models.php.

When you enable this feature your models will inherit their base configurations from base models. You should avoid adding code to your base models, since you will lose all changes when they are generated again.

Note: You will end up with two models for the same table and you may think it is a horrible idea to have two classes for the same thing. However, it is up to you to decide whether this approach gives value to your project :-)

Support

For the time being, this package supports MySQL, PostgreSQL and SQLite databases. Support for other databases are encouraged to be added through pull requests.

laravel's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel's Issues

Table names without schema

Am working on a dynamic database system that changes DB depending on user organization,

How do I remove the schema from the model table name;

From;
protected $table = 'schema.table_name';

to;

protected $table = 'table_name';

Will appreciate, quite stuck with this after hours of debugging.

Regards.

Code:Models doesn't generate anything

I am using Laravel 5.3 and I followed the instructions for installing this. After I issued the command: "php artisan code:models", it says: "Check out your models for [database name]". But when I navigate through my project folder under app/Models, the directory is empty. No models have been generated. I tried running CMD with administrative privileges and nothing happens. I tried searching the whole project folder and no models has been generated. Does anyone else encountered this problem?

mkdir(): Invalid path

I'm using laravel 5.4.9 & reliese newest version to fix fetch...
but i have issue when run

php artisan code:models

[ErrorException]
mkdir(): Invalid path

I tried create folder Models in App, but still error

When performing the generation of models you may want to take some of them

Example:
A package can exclude selected tables:

'except'       => [
    'migrations',
],

But there is a situation that the database contains many tables (for example, 197 like mine), and it is necessary to generate models for only four of them.

I suggest adding the "only" key to define the list of tables for which the models will be generated.

Parameter must be an array or an object that implements Countable

I created a clean project on Laravel with the MySQL 5.7 database and PHP 7.2RC2.
I connected only your package, and performed one by one:

php artisan migrate:install
php artisan code:models

I get an error:

[2017-10-24 10:44:34] local.ERROR: count(): Parameter must be an array or an object that implements Countable {"exception":"[object] (ErrorException(code: 0): count(): Parameter must be an array or an object that implements Countable at C:\\OpenServer\\domains\\test123\\vendor\
eliese\\laravel\\src\\Coders\\Model\\Model.php:684)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'count(): Parame...', 'C:\\\\OpenServer\\\\d...', 684, Array)
#1 C:\\OpenServer\\domains\\test123\\vendor\
eliese\\laravel\\src\\Coders\\Model\\Model.php(684): count(NULL)
#2 C:\\OpenServer\\domains\\test123\\vendor\
eliese\\laravel\\src\\Coders\\Model\\Factory.php(309): Reliese\\Coders\\Model\\Model->hasCustomPrimaryKey()
#3 C:\\OpenServer\\domains\\test123\\vendor\
eliese\\laravel\\src\\Coders\\Model\\Factory.php(233): Reliese\\Coders\\Model\\Factory->body(Object(Reliese\\Coders\\Model\\Model))
#4 C:\\OpenServer\\domains\\test123\\vendor\
eliese\\laravel\\src\\Coders\\Model\\Factory.php(148): Reliese\\Coders\\Model\\Factory->fillTemplate('<?php\
\
/**\
 * C...', Object(Reliese\\Coders\\Model\\Model))
#5 C:\\OpenServer\\domains\\test123\\vendor\
eliese\\laravel\\src\\Coders\\Model\\Factory.php(118): Reliese\\Coders\\Model\\Factory->create('helpers', 'password_resets')
#6 C:\\OpenServer\\domains\\test123\\vendor\
eliese\\laravel\\src\\Coders\\Console\\CodeModelsCommand.php(69): Reliese\\Coders\\Model\\Factory->map('helpers')
#7 [internal function]: Reliese\\Coders\\Console\\CodeModelsCommand->handle()
#8 C:\\OpenServer\\domains\\test123\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(29): call_user_func_array(Array, Array)
#9 C:\\OpenServer\\domains\\test123\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#10 C:\\OpenServer\\domains\\test123\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#11 C:\\OpenServer\\domains\\test123\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(549): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#12 C:\\OpenServer\\domains\\test123\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(180): Illuminate\\Container\\Container->call(Array)
#13 C:\\OpenServer\\domains\\test123\\vendor\\symfony\\console\\Command\\Command.php(262): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#14 C:\\OpenServer\\domains\\test123\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(167): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#15 C:\\OpenServer\\domains\\test123\\vendor\\symfony\\console\\Application.php(888): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 C:\\OpenServer\\domains\\test123\\vendor\\symfony\\console\\Application.php(224): Symfony\\Component\\Console\\Application->doRunCommand(Object(Reliese\\Coders\\Console\\CodeModelsCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 C:\\OpenServer\\domains\\test123\\vendor\\symfony\\console\\Application.php(125): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 C:\\OpenServer\\domains\\test123\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Application.php(88): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 C:\\OpenServer\\domains\\test123\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(121): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 C:\\OpenServer\\domains\\test123\\artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 {main}
"} 

helpers - it's name of database.

"hasPivot" method unexpected behavior with belongsToMany relations

$pivot = str_replace($firstRecord, '', $pivot);

If the 1st table is "orgs" and 2nd table is "org_classes" and the pivot is "org_org_class", this line will produce "org_" in the first round, and "__class" in second round. Obviously because it's removing the "org" key twice from the name.

I think the solution would be to check if the pivot "starts with" or "ends with" instead of "contains". And remove accordingly.

Regards,

Laravel 5.5

I doesnt generate the models in Laravel 5.5, check it out

Issue with model names

First of all, amazing work!

I'm having a bit of a problem with how some model names end up differently as to how they are defined in the database. The app I want to migrate to Laravel is developed in portuguese, and database table names are also in portuguese. I have around 100 tables and growing.

It seems the getRecordName method in Reliese\Coders\Model\Model calls Str::singular, which doesn't always play nice with non english words. Words like agencia (agency) turn into agencium, pais (country) turn into pai (father), etc., so I'm ending up with model names that don't follow Laravel's conventions when they would if the original name was used. Some of these singular forms don't make sense at all or they completely change the meaning of the word.

It normally wouldn't be a problem for me to change it manually, but this application is being actively developed, so I'll need to generate models periodically, and it's affecting several models.

Is there a way to make this configurable?

Blobs are being represented as booleans

Looking over our model files I found that the generator is setting longblob and blob as boolean. But mediumblob gets set to mediumblob. This seems like an incorrect classification and not constant across the board. Is boolean the proper classification

Unknown column 'BASE TABLE' in 'where clause'

I'm using a connection to two databases in Laravel 5.5 project with MySQL 5.719:

.env:

DB_CONNECTION=mysql
DB_INFO_CONNECTION=information

In MySQL, there are several tables, the first of which is discount.

When I call the php artisan code:models command (and php artisan code:models --connection=information, and php artisan code:models --connection=mysql, and php artisan code:models --table=users), I get an error:

[Illuminate\Database\QueryException]
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BASE TABLE' in 'where clause' (SQL: SHOW FULL TABLES FROM `discount` WHERE Table_type="BASE TABLE")

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BASE TABLE' in 'where clause'

[PDOException]
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BASE TABLE' in 'where clause'

Stack Trace:

[2017-10-24 13:09:10] local.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BASE TABLE' in 'where clause' (SQL: SHOW FULL TABLES FROM `discount` WHERE Table_type="BASE TABLE") {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BASE TABLE' in 'where clause' (SQL: SHOW FULL TABLES FROM `discount` WHERE Table_type=\"BASE TABLE\") at C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:664, Doctrine\\DBAL\\Driver\\PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BASE TABLE' in 'where clause' at C:\\OpenServer\\domains\\myproject.dev\\vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Driver\\PDOConnection.php:79, PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BASE TABLE' in 'where clause' at C:\\OpenServer\\domains\\myproject.dev\\vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Driver\\PDOConnection.php:77)
[stacktrace]
#0 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php(624): Illuminate\\Database\\Connection->runQueryCallback('SHOW FULL TABLE...', Array, Object(Closure))
#1 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php(333): Illuminate\\Database\\Connection->run('SHOW FULL TABLE...', Array, Object(Closure))
#2 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Meta\\MySql\\Schema.php(80): Illuminate\\Database\\Connection->select('SHOW FULL TABLE...')
#3 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Meta\\MySql\\Schema.php(64): Reliese\\Meta\\MySql\\Schema->fetchTables('discount')
#4 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Meta\\MySql\\Schema.php(47): Reliese\\Meta\\MySql\\Schema->load()
#5 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Meta\\SchemaManager.php(86): Reliese\\Meta\\MySql\\Schema->__construct('discount', Object(Illuminate\\Database\\MySqlConnection))
#6 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Meta\\SchemaManager.php(74): Reliese\\Meta\\SchemaManager->makeMapper('discount')
#7 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Meta\\SchemaManager.php(59): Reliese\\Meta\\SchemaManager->make('discount')
#8 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Meta\\SchemaManager.php(44): Reliese\\Meta\\SchemaManager->boot()
#9 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Coders\\Model\\Factory.php(100): Reliese\\Meta\\SchemaManager->__construct(Object(Illuminate\\Database\\MySqlConnection))
#10 C:\\OpenServer\\domains\\myproject.dev\\vendor\
eliese\\laravel\\src\\Coders\\Console\\CodeModelsCommand.php(69): Reliese\\Coders\\Model\\Factory->on('information')
#11 [internal function]: Reliese\\Coders\\Console\\CodeModelsCommand->handle()
#12 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(29): call_user_func_array(Array, Array)
#13 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#14 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#15 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(549): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#16 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(180): Illuminate\\Container\\Container->call(Array)
#17 C:\\OpenServer\\domains\\myproject.dev\\vendor\\symfony\\console\\Command\\Command.php(262): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#18 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(167): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#19 C:\\OpenServer\\domains\\myproject.dev\\vendor\\symfony\\console\\Application.php(888): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 C:\\OpenServer\\domains\\myproject.dev\\vendor\\symfony\\console\\Application.php(224): Symfony\\Component\\Console\\Application->doRunCommand(Object(Reliese\\Coders\\Console\\CodeModelsCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 C:\\OpenServer\\domains\\myproject.dev\\vendor\\symfony\\console\\Application.php(125): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Application.php(88): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#23 C:\\OpenServer\\domains\\myproject.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(121): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#24 C:\\OpenServer\\domains\\myproject.dev\\artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#25 {main}
"} 

Laravel 5.4

I have try this with the new laravel and it didn't work.
Do you know why? Can you fix it?

Should it be Generating Pivot Tables?

I have the usual users, roles and users_roles table as defined here

CREATE TABLE `users` (
  `user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `username` VARCHAR(45) NOT NULL,
  `email` VARCHAR(190) NOT NULL,
  PRIMARY KEY (`user_id`),
  UNIQUE INDEX `username_UNIQUE` (`username` ASC),
  UNIQUE INDEX `email_UNIQUE` (`email` ASC))

CREATE TABLE `users_roles` (
  `user_id` INT UNSIGNED NOT NULL,
  `role_id` INT UNSIGNED NOT NULL,
  INDEX `fk_users_roles_users_idx` (`user_id` ASC),
  INDEX `fk_users_roles_roles_idx` (`role_id` ASC),
  PRIMARY KEY (`user_id`, `role_id`),
  CONSTRAINT `fk_users_roles_users`
    FOREIGN KEY (`user_id`)
    REFERENCES `users` (`user_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_users_roles_roles`
    FOREIGN KEY (`role_id`)
    REFERENCES `roles` (`role_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)

CREATE TABLE  `roles` (
  `role_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  `label` VARCHAR(45) NOT NULL,
  `description` VARCHAR(100) NULL,
  PRIMARY KEY (`role_id`))

Currently, it will generate a Model for all three tables including the pivot table roles_users. Should it be generating a UsersRole model? or is this a bug? I go through and delete them after every generate.

Thanks,

Really useful tool!

Asking for help

I am putting Artisan:call to let it run "php artisan code:models"
But it shows this error. It like the php artisan code was undefined. How to solve it mates. I need your assistance. Thank You
image
image

There are no commands defined in the "php artisan code" namespace.

[Symfony\Component\Debug\Exception\FatalErrorException]

Laravel 5.5

Running php artisan code:models --schema=password_reset will result in:

Allowed memory size of 1073741824 bytes exhausted (tried to allocate 1702244232 bytes) in /home/medpets/WWW/laravel/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php on line 105
PHP Stack trace:
PHP   1. {main}() /home/medpets/WWW/laravel/artisan:0
PHP   2. Illuminate\Foundation\Console\Kernel->handle() /home/medpets/WWW/laravel/artisan:35
PHP   3. Illuminate\Console\Application->run() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:121
PHP   4. Symfony\Component\Console\Application->run() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Console/Application.php:88
PHP   5. Symfony\Component\Console\Application->doRun() /home/medpets/WWW/laravel/vendor/symfony/console/Application.php:125
PHP   6. Symfony\Component\Console\Application->doRunCommand() /home/medpets/WWW/laravel/vendor/symfony/console/Application.php:224
PHP   7. Illuminate\Console\Command->run() /home/medpets/WWW/laravel/vendor/symfony/console/Application.php:888
PHP   8. Symfony\Component\Console\Command\Command->run() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php:167
PHP   9. Illuminate\Console\Command->execute() /home/medpets/WWW/laravel/vendor/symfony/console/Command/Command.php:262
PHP  10. Illuminate\Container\Container->call() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php:180
PHP  11. Illuminate\Container\BoundMethod::call() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:549
PHP  12. Illuminate\Container\BoundMethod::callBoundMethod() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
PHP  13. Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
PHP  14. call_user_func_array:{/home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29}() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
PHP  15. Reliese\Coders\Console\CodeModelsCommand->handle() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
PHP  16. Reliese\Coders\Model\Factory->on() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Coders/Console/CodeModelsCommand.php:69
PHP  17. Reliese\Meta\SchemaManager->__construct() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Coders/Model/Factory.php:100
PHP  18. Reliese\Meta\SchemaManager->boot() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Meta/SchemaManager.php:44
PHP  19. Reliese\Meta\SchemaManager->make() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Meta/SchemaManager.php:59
PHP  20. Reliese\Meta\SchemaManager->makeMapper() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Meta/SchemaManager.php:74
PHP  21. Reliese\Meta\MySql\Schema->__construct() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Meta/SchemaManager.php:86
PHP  22. Reliese\Meta\MySql\Schema->load() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Meta/MySql/Schema.php:47
PHP  23. Reliese\Meta\MySql\Schema->fillConstraints() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Meta/MySql/Schema.php:68
PHP  24. Illuminate\Database\Connection->select() /home/medpets/WWW/laravel/vendor/reliese/laravel/src/Meta/MySql/Schema.php:114
PHP  25. Illuminate\Database\Connection->run() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
PHP  26. Illuminate\Database\Connection->runQueryCallback() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
PHP  27. Illuminate\Database\Connection->Illuminate\Database\{closure}() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
PHP  28. Doctrine\DBAL\Driver\PDOStatement->execute() /home/medpets/WWW/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:330
PHP  29. PDOStatement->execute() /home/medpets/WWW/laravel/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:105

Get error when generate models

I used "ignasbernotas/laravel-model-generator" package before and I see "Please use reliese/laravel package instead."
Now, I use Laravel 5.4 and have an exists database in MySQL. I want to generate models.
When I run "php artisan code:models" I receive the error:
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY093]: Invalid parameter number: mixed named and positional param
eters
[PDOException]
SQLSTATE[HY093]: Invalid parameter number: mixed named and positional param
eters
Please help me. Thanks.

Snake case function names

I see that there is a property of snake_attributes in config/models.php. My column name is the MySQL database are snake cased, however, I’d like the to be camelCase in the model definitions

Is it possible to have the column names be camelCased?

Issue by generate models

Hello,

i´m getting this error, when I try to generate the models:

Call to undefined method Illuminate\Database\MySqlConnection::setFetchMode()

Maybe you can help me?!

Thank you very much!

Add a destination directory option for generated model

Hey, this is an excellent package. Thank you for taking time to make this.

I use a little different kind of directory structure. Refer to the example given below.

- app
    - Domain
        - User
            - User.php (file generate by your package)
            - Base (folder generate by your package)
                - User.php (file generate by your package)
        - Role
            - Role.php (file generate by your package)
                - Base (folder generate by your package)
                    - Role.php (file generate by your package)

So can we add and one more argument to the command to override the config file to generate in the following structure?

php artisan code:models --table=users --src="Domain/User"

Table with Multiple relationships to One table

I have a table that has two fields where those two fields are associated with the same column from one other table. When the models get generated, the eloquent relationship only creates one of them, not both.

How can I make sure that both get created, or is this a bug or currently something that is not yet supported?

Example:

Account
---Id
....

Asset
---Id (pkid)
---AccountId (contains an account id - foreign key on this column referencing Account.Id)
---ResellerId (contains an account id - foreign key on this column referencing Account.Id)
....

Return Type Specification in PHP 7

Hi,
I simply want to request that, if available, the module returns another model type for relationship generation in php 7.

Simply put, if I have a model users with a key book-id, normally the module would generate a model User with book() as a method. So, in php7, we can allow the book() to specify the return type Book as part of the method signature.

This would increase productivity as several IDEs can suggest properties and methods of the other chained object and would immensely reduce coding and debugging time.

Also, new devs would easily get the flow of the project since they don't always have to go back to the model class to check the properties before they can work on any part they want to.

Error when running php artisan code:models

Thanks for providing this nice package. Installed it on a fresh 5.3 installation with MySQL + Laravel Boilerplate by Anthony Rappa.

All migrations run normally however after running: php artisan code:models the following errors appear (same goes for scaffolding a specific table while running php artisan code:models --table=users)

Would be nice to receive a suggestion on where I can best start looking to resolve this issue

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for t
he right syntax to use near '53' at line 1 (SQL: SHOW TABLES FROM 53)

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for t
he right syntax to use near '53' at line 1

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for t
he right syntax to use near '53' at line 1

Fillable property on BaseModels

I would like to suggest the fillable property show be keeped on Base files, and only be overloaded if nedded on Model files.

Are you accepting pull requests?

Merge Casting with BaseModel and Model

Allow user to add Custom Casting on UserModel File that will be merged with BaseModel casting attribute.
because some time we need to add our own casting attributes and when we recompile our models then that casting attribute are also overiden.

i have achived it by defining custom Casting array in Model and then merge it with BaseModel casting array in BaseModel contructor

Plural form of Child becomes Childrens

Just came across a minor thing...

In my project there is a table called "children". In the schema, the following foreign key is created:

$table->foreign('individual_id')->references('id')->on('individuals')->onDelete('cascade');

The "child" model is created correctly with your script. However, in the "individual" model the following function is created:

public function childrens()
{
    return $this->hasMany(\App\Models\Child::class);
}

Have manually renamed "childrens" to "children" so no problem.

Problem when passing array to property with json cast

I'm getting this error when I try to pass an array to a model property that is cast as json.

The generator made the entire class by itself, and those are the field generated stuff:

/*
* @property array $extra_fields
*/

protected $casts = [
    'extra_fields' => 'json'
];

Exception:

image

The tool created the model adding this use clause:

use Reliese\Database\Eloquent\Model as Eloquent;

When I switched it to the Illuminate class, it worked.

use Illuminate\Database\Eloquent\Model as Eloquent;

Can this be fixed or is there a way to use Illuminate classes instead of classes from the Reliese namespace?

Enhancement: Column mapping needed

Hi,

I have one large database which have 150+ tables and in most of the table fields has unstructured column naming like some have Snake case (with Uppercase) and some have Camel Cases. So I want to generate model classes in such a way that all the class attribute should be in camel cases and model class can refer some thing like

@ColumnMapping ('USER_NAME')
private userName;

Please suggest me some of the solution for the same. I got that column mapping idea from JPA (In Java Spring MVC framework)

Thanks,
Anil

Error running 'php artisan code:models' mysql query appears to be missing backticks

The command kicked out with the error messages below. It appears that the SQL statement "SHOW FULL COLUMNS FROM dcdb.active-web-products" whereas it should be "SHOW FULL COLUMNS FROM `dcdb`.`active-web-products`"

ERRORS:

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-web-products' at line 1 (SQL: SHOW FULL COLUMNS FROM dcdb.active-web-products)

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-web-products' at line 1

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-web-products' at line 1

Generating model name problems

The table name user_data generates UserDatum.php instead of UserData.php
Although I know my name has a problem, but it should not be so

Please make a release

Hi! great library, I love it! Please make a release, so we don't have to write

"reliese/laravel": "dev-master"

in our composer.json. Thanks!

RunTimeException exception when trying to generate models from Postgres database

Hi thank you for this tool.

I am experiencing an issue though. When I run php artisan code:models I get the following RunTimeException exception

There is no Schema Mapper registered for [Illuminate\Database\PostgresConnection] connection.

I am using Postgres database and my connection looks like

'pgsql' => [
'driver' => 'pgsql',
'host' => 'localhost',
'port' => '5432',
'database' => 'test',
'username' => 'postgres',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],

Thank you.

mkdir(): Invalid path

Getting the following error when running php artisan code:models --table=sales_executive :

[ErrorException]
mkdir(): Invalid path

My config file is present in ./config/models.php and was created by CLI with: php artisan vendor:publish --tag=reliese-models.

Debugging $this->config in CodersServiceProvider says:

class Reliese\Coders\Model\Config#194 (1) {
  protected $config =>
  NULL
}

Any ideas?

Removes intended 's' at end of table name.

First, you've made an excellent tool!

I have tables that I've created with a couple of migrations that are named

ShankOutsideDiameterCps
PartBasePartShankOutsideDiameterCps

The suffix, "Cps", is an abbreviation of a product type name that we sell and intended to be listed as Cps. When I run,

$bash> php artisan code:models

The tool is being confused about the pluralization of the table name and removing the "s" at the end of the table name. The resulting models being generated are:

ShankOutsideDiameterCp
PartBasePartShankOutsideDiameterCp

I believe that the code that's doing this is here.

Is this correct? Is it possible to have my desired outcome?

Invalid Argument supplied for foreach

Laravel 5.3
I am getting an Invalid Argument supplied for foreach error when using php artisan code:models

I traced it back to Models line 1036

I fixed it by checking if primaryKeys->columns is an array before processing the foreach block
Updated code is below

Please confirm and add this possible fix if you want.

public function isPrimaryKey(Fluent $command)
    {
        if(is_array($this->primaryKeys->columns)){

            foreach ($this->primaryKeys->columns as $column) {
                if (! in_array($column, $command->columns)) {
                    return false;
                }
            }

        }

        return true;
    }

Creating model folders based on the tables prefixes

Example, I have tables in one database:

gallery_marks
gallery_models
gallery_modifications
gallery_cars
news_categories
news_posts
news_other_tables
images

Now the package will create all models in the folder 'path' => app_path('Models'),

It will be fine if you can set the prefixes of the tables in the configuration to generate the models in the subfolders.

Example:

 'tables_prefixes' => [
    'gallery', 'news'
 ],

And when the command was run, the models in the folder path would be created:

Gallery/Mark::class
Gallery/Model::class
Gallery/Modification::class
Gallery/Car::class
News/Category::class
News/Post::class
News/OtherTable::class
Images::class

// And based models:
Base/Gallery/Mark::class
Base/Gallery/Model::class
Base/Gallery/Modification::class
Base/Gallery/Car::class
Base/News/Category::class
Base/News/Post::class
Base/News/OtherTable::class
Base/Images::class

It would be cool 🙂

mkdir(): Invalid path

I try use other issues solutions but don't work

I used
php artisan vendor:publish --tag=reliese-models

its work, but when I try use a

php artisan code:models
display a error

[ErrorException] mkdir(): Invalid path

HasOne relationship...

Hello again! Let's say i have two models:
Human and Brain
it is one-to-one (hasOne) relationship.

Currently code:models generates
public function brains() { return $this->hasMany(\App\Brain::class); }
instead of
public function brain() { return $this->hasOne(\App\Brain::class); }
in Human model.

Is there any way, i can tell the library to use hasOne instead of hasMany? I didn't find any. I also wanted to make it on my own (and create pull request), but then I looked at the code. It is beautiful. But too complex for me, no matter how hard i tried to understand it :-( . Maybe you can tell direction (location of code to edit) and i can make it?

P.S. Only then, when i've looked at your code, i have really understood, how much work was made by you. Have my big respect.

Incorrectly specifies the $connection parameter when working with multiple connections.

.env:

DB_CONNECTION=mysql
DB_HOST=1.2.3.4
DB_PORT=3306
DB_DATABASE=helpers
DB_USERNAME=homestead
DB_PASSWORD=secret

DB_AVA_CONNECTION=finance
DB_AVA_HOST=1.2.3.4
DB_AVA_PORT=3306
DB_AVA_DATABASE=finance
DB_AVA_USERNAME=my_login
DB_AVA_PASSWORD=my_password

config/database.php:

<?php
  // ...
  'connections' => [
        'mysql' => [
            'driver'      => 'mysql',
            'host'        => env('DB_HOST', '127.0.0.1'),
            'port'        => env('DB_PORT', '3306'),
            'database'    => env('DB_DATABASE', 'forge'),
            'username'    => env('DB_USERNAME', 'forge'),
            'password'    => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset'     => 'utf8mb4',
            'collation'   => 'utf8mb4_unicode_ci',
            'prefix'      => '',
            'strict'      => true,
            'engine'      => null,
        ],

        'finance' => [
            'driver'      => 'mysql',
            'host'        => env('DB_AVA_HOST', '127.0.0.1'),
            'port'        => env('DB_AVA_PORT', '3306'),
            'database'    => env('DB_AVA_DATABASE', 'forge'),
            'username'    => env('DB_AVA_USERNAME', 'forge'),
            'password'    => env('DB_AVA_PASSWORD', ''),
            'unix_socket' => env('DB_AVA_SOCKET', ''),
            'charset'     => 'utf8mb4',
            'collation'   => 'utf8mb4_unicode_ci',
            'prefix'      => '',
            'strict'      => true,
            'engine'      => null,
        ],
  ]

config/models.php:

<?php

return [

    '*' => [

        'path' => app_path('Models'),
        'namespace' => 'MYAPP\Models',
        'parent' => Illuminate\Database\Eloquent\Model::class,

        'use' => [
            // Reliese\Database\Eloquent\BitBooleans::class,
            // Reliese\Database\Eloquent\BlamableBehavior::class,
        ],

        'connection' => true,
        'timestamps' => true,
        'soft_deletes' => true,
        'date_format' => 'Y-m-d H:i:s',
        'per_page' => 15,
        'base_files' => true,
        'snake_attributes' => true,
        'qualified_tables' => true,
        'hidden' => [
            '*secret*',
            '*password',
            '*token',
        ],
        'guarded' => [
            // 'created_by', 'updated_by'
        ],
        'casts' => [
            '*_json' => 'json',
        ],
        'except'       => [
            'migrations',
            'users',
            'password_resets',
            'failed_jobs',
            'jobs',
            'subscribe_users',
            'oauth_access_tokens',
            'oauth_auth_codes',
            'oauth_clients',
            'oauth_personal_access_clients',
            'oauth_refresh_tokens',
            'spammers',
            'spammer_accesses',
        ],
        'table_prefix' => '',
    ],

    'helpers' => [
        'path'             => app_path('Models/Main'),
        'namespace'        => 'MYAPP\Models\Main',
        'connection'       => true,
        'timestamps'       => true,
        'soft_deletes'     => true,
        'base_files'       => true,
        'snake_attributes' => true,
        'qualified_tables' => true,
    ],

    'finance' => [
        'path'             => app_path('Models/Finance'),
        'namespace'        => 'MYAPP\Models\Finance',
        'connection'       => true,
        'timestamps'       => true,
        'soft_deletes'     => true,
        'base_files'       => true,
        'snake_attributes' => true,
        'qualified_tables' => true,
    ],
];

When I execute the command art code:models --schema=helpers, a base model is generated:

protected $connection = 'mysql';
protected $table = 'helpers.gallery_cars';

Alright!

Next, i execute art code:models --schema=finance and I get code:

protected $connection = 'mysql';
protected $table = 'finance.di_brand';

See the $connection attrubute... It contains the value mysql instead of finance...

Write a `$fillable` attribute into `base` models

When I change the value of the parameter base_files to true, when executing the command for generating models, the attribute $fillable is written to the file of the main model.
After that, I can make changes to the structure of the database by creating a migration.
Since the fields in the $fillable attribute are already obsolete, instead of manually adding new fields to the list, I prefer to run the command art code:models again.
In this case, the value of the attribute $fillable will not be overwritten.

Inheriting Authenticatable

Hi,

The user model (by default) inherits Illuminate\Foundation\Auth\User as Authenticatable, however, the generated models inherit the Reliese\Database\Eloquent\Model.

In the current version we are unable to use both. Please suggest a solution to use both or add a feature to the package to solve it.

This package is a very good package! I really like.

Regards,

Table Naming conventions

This is a wonderful package. But through my research in the code - which came in response to the problem that some belongsToMany relations were not being generated properly - I learned that the you've assumed some naming conventions for pivot tables for the code to work correctly.

We would appreciate it if those conventions are published in the README.

Regards,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.