Giter Site home page Giter Site logo

laravel-model-generator's Introduction

✌️

👋 Hi, I'm Ignas

Software Engineer, Team Lead

🤝🏻 Connect with me

sadv1r ignasbernotas

laravel-model-generator's People

Contributors

c-harris avatar charlyr avatar estebanprimost avatar hooklife avatar ignasbernotas avatar jacobsantos avatar joseluisq avatar tomsowerby avatar wutherland avatar

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

laravel-model-generator's Issues

Project abandoned

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.

Table Names not Created

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.

Feature request: SetGetGenerator to generate also relations

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.

rtrim for s sufix issue

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

laravel5.4.9 setFetchMode()

[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Illuminate\Database\MySqlConnection::setFetchMode()

Namespace and classname remain Dummy___

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.

Request: Primary Key Detection

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'
];

Command "make:models" is not defined.

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?

artisan command

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

Unable to Execute Command

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()

not being able to install it

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

A little bit of advice

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!

Handle fetch type in making models

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.)

variable tables does not exist

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

Use of `--dir /` causes extra character in Model file.

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.

Doesn't support table prefixes

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.

why generator models is not table 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 = [];
}

getters and setters

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.

Include relations

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?

php artisan command getting error

  • Laravel Version: 5.2.45
  • PHP Version:5.5.9
  • Database Driver & Version: mysql 5.0.11

Description:

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)

please help me on this

Steps To Reproduce:

  • after running composer update getting this error
  • checkout older version of code running that running fine also get this error, I have tried with removing entire db, vendor, composer.lock,bootstrap cache folder files, but nothing solve this. lase tried composer update --no-dev, composer update --no-script, composer dumpautoload every thing

Generated model class styling

  • The opening php tag should follow with a newline as such:
<?php 
namespace App\Models;
  • Remove unnecessary spacing when certain stub variables are left out empty.

Problem with postgre sql

[Illuminate\Database\QueryException]
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "" LINE 1: SELECT table_name ASnameFROM information_schema.tables W... ^ (SQL: SELECT table_name ASname` 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 ASname` FROM information_schema.tables W...
^

seam that's not compatible with Postgres schemas

return database query and PDO execption :

SQLSTATE[42601]: Syntax error: 7 ERREUR: syntaxe errore near "" LINE 1: SELECT table_name ASname` 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 ?

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.