Software Engineer, Team Lead
ignasbernotas / laravel-model-generator Goto Github PK
View Code? Open in Web Editor NEWLaravel 5 model generator for an existing schema
Laravel 5 model generator for an existing schema
The new standard for laravel 5 is to place models in App instead of App/models, so maybe it's good to change the default to App, and let people manually give the option to place it in Models.
I'm very sorry to announce that I no longer have time to maintain this package. This project was originally created over a couple of days when I needed to migrate an existing project onto Laravel. Even though it's being actively used (over 50k installs!), I can't find the time to keep track of the PRs and what changes might break things in new/old Laravel versions, nor have I had the need to use it after the initial release. The codebase is a mess and it desperately cries for a rewrite.
I'm happy to hand it over to someone who is an active open-source community contributor and is willing to keep the package running.
Your readme is incorrect, the package does not produce a $table
property in the model, since it's not included in the stub:
<?php
namespace DummyNamespace;
use Illuminate\Database\Eloquent\Model;
/**
* Class DummyClass
*/
class DummyClass extends {{extends}}
{
{{timestamps}}
{{fillable}}
{{guarded}}
{{getters}}
{{setters}}
}
Please either adjust the readme or the package for accuracy.
Thanks.
Hello, is it possible that the SetGetGenerator also generates relations, making use of the foreign keys defined in the schema ? Example:
/**
* retrieve related table relTable
* @return mixed
*/
public function relTable() {
return $this->hasOne('App\Models\RelTable', 'id', 'relTableID'); // one to one relation
}
That would be a major improvement. Thanx for your valuable work, Thomas
Oh --- I just saw that you already thought about that in #9 (closed), and marked it, sadly, as wontfix. What a pity.
This library automatically remove all "s" from the end of a table name. It's good idea, but this option should be controlled by some command line parameter. For example if we got table called "address" then class generated is called "addre" - and that's the case which I had.
If I good understand the code it's at MakeModelsCommand:147:
$name = rtrim($this->parseName($prefix . $class), 's');
Would You mind to make such change?
Regards
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Illuminate\Database\MySqlConnection::setFetchMode()
The tokens, DummyClass
and DummyNamespace
, never get replaced. Namespace is already supported via options, so it's a little confusing to set a namespace and never have it take effect (aside from setting which directory it goes into).
Also unexpected to have the filename be correct, but the class name remain DummyClass.
Determine if primary key is the standard id
or not.
If not, create primary key property and remove the primary key field from the $fillable
array.
Example:
CREATE TABLE `order_product` (
`order_product_id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`model` varchar(64) NOT NULL,
`quantity` int(4) NOT NULL,
`price` decimal(15,4) NOT NULL DEFAULT '0.0000',
`total` decimal(15,4) NOT NULL DEFAULT '0.0000',
`tax` decimal(15,4) NOT NULL DEFAULT '0.0000',
`reward` int(8) NOT NULL,
PRIMARY KEY (`order_product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Would produce:
protected $primaryKey = 'order_product_id';
protected $fillable = [
'order_id',
'product_id',
'name',
'model',
'quantity',
'price',
'total',
'tax',
'reward'
];
I tried using it with lumen -- following the install directions, but "php artisan make:models" gives this error:
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "make:models" is not defined.
Did you mean this?
make:migration
Am I doing something wrong, or is this not supported with lumen?
Hello dear Sir,
I have an issue running the command:
php artisan make:models
It says: undefined variable: tables
I've looked in the MakeModelsCommand class, on that moment when it runs getSchemaTables function, the env('DB_CONNECTION') is undefined.
Could you please help me?
With kind regards,
Ruzalin
Hi, im using laravel 5.3 and I was not able to execute the command php artisan migrate:models
after installing the package. I got the following error message.
Call to undefined method Iber\Generator\Commands\MakeModelsCommand::qualifyClass()
hi please guide to install , where do we place the folder , installation guide incomplete
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Iber\Generator\ModelGeneratorProvider' not found
I think that it should have been established to skip, or be configurable! Just now, I have the project I have established the Model, and then in the use of this, and then there are a lot of duplication! It let me had to go back code!
Translate by Google!
Currently in MakeModelsCommand line 109 we have $this->generateTable($table->name)
;
However the -> operator only works if the fetch style in database.php is 'FETCH_CLASS
'. Some devs prefer'FETCH_ASSOC'
to make the SQL results arrays of arrays, not arrays of objects. The problem is that it also fails without any clue to the cause.
The code should take this into consideration.
(I can handle it via a MR today or tomorrow, if you want.)
After installation, any attempt to execute resulted in the error "variable tables does not exist" (exact message might be slightly off because I fixed it ;-)
I traced it to the use of configuration information. The code assumes the default database connection name is one of a few values (mysql, pgsql, etc.) that would also be the name of the database driver.
I use multiple (mysql) database connections in my app and my default database connection is not named mysql.
Renaming it fixed the problem for tests, but I also patched the code. I'll probably be asked to submit patch or proposed change, but this is my first GitHub issue report and possible bugfix so bear with me.
Thx
PHP: 7.1.4
Laravel: 5.1.46 LTS
Running this command: php artisan make:models --tables group_practice_type -vvv --dir /
Outputs the file app/GroupPracticeType.php
thus:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* Class \GroupPracticeType
*/
class \GroupPracticeType extends Model
{
protected $table = 'group_practice_type';
protected $primaryKey = 'group_practice_type_id';
public $timestamps = true;
protected $fillable = [
'group_practice_nm',
'group_practice_cd',
'group_practice_dsc',
'order_num'
];
protected $guarded = [];
}
Note the backslash on line 10 preceding the class name.
This appears to work perfectly for my purposes with the small exception that it doesn't support prefixes - in that I would like to omit the prefix from the model name.
generator code:
/**
* App\Models\Invoice
*
*/
class Invoice extends Model {
public $timestamps = false;
protected $fillable = ['orders', 'uid', 'address', 'state', 'remark', 'invoice_amount', 'created'];
protected $guarded = [];
}
Hi, how to incluse getters and setters, if I laugh command with --getset
option, all getters and setters of my models are empty.
php artisan make:oc-models --getset
Thank you.
We can support mongodb (https://github.com/jenssegers/laravel-mongodb) with your generator ?
/** @property integer $id */
/** @property string $data */
class EventData extends Model
{
protected $table = 'events_data';
}
Can you tell me how to solve this problem?
This isn't really an issue but I thought I'd raise the idea and open discussion.
It would be excellent if this libary added relations to the models for you.
The sql to see these:
SELECT
`TABLE_SCHEMA`, -- Foreign key schema
`TABLE_NAME`, -- Foreign key table
`COLUMN_NAME`, -- Foreign key column
`REFERENCED_TABLE_SCHEMA`, -- Origin key schema
`REFERENCED_TABLE_NAME`, -- Origin key table
`REFERENCED_COLUMN_NAME` -- Origin key column
FROM
`INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` -- Will fail if user don't have privilege
WHERE
`TABLE_SCHEMA` = SCHEMA() -- Detect current schema in USE
AND `REFERENCED_TABLE_NAME` IS NOT NULL; -- Only tables with foreign keys
I personally feel that to keep the scope small, assuming a one (from origin) to many (on foreign) would be ok.
Perhaps it should only do this is a certain flag is provided?
Thoughts?
running > php artisan command getting this error
PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\xampp\htdocs\ctw-portal\vendor\ignasbernotas\laravel-model-generator\src\Commands\MakeModelsCommand.php on line 121
[Symfony\Component\Debug\Exception\FatalErrorException]
syntax error, unexpected '->' (T_OBJECT_OPERATOR)
<?php
namespace App\Models;
php :7.1.20
mysql:5.7.19
laravel:5.6.29
I am using Laravel 5.4. I got following error after correcting setFetchMode issue.
Call to undefined method Iber\Generator\Commands\MakeModelsCommand::parseName()
in vendor\ignasbernotas\laravel-model-generator\src\Commands\MakeModelsCommand.php on line 178
[Illuminate\Database\QueryException]
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "" LINE 1: SELECT table_name AS
nameFROM information_schema.tables W... ^ (SQL: SELECT table_name AS
name` FROM infor
mation_schema.tables WHERE table_schema = DATABASE())
[PDOException]
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "" LINE 1: SELECT table_name AS
name` FROM information_schema.tables W...
^
return database query and PDO execption :
SQLSTATE[42601]: Syntax error: 7 ERREUR: syntaxe errore near "" LINE 1: SELECT table_name AS
name` FROM information_schema.tables W...
I think that's because the "`" char is not the convention in postgres to call sq.
Any way tyo use it with postgres ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.