pepijnolivier / eloquent-model-generator Goto Github PK
View Code? Open in Web Editor NEWAuto-generates all Eloquent models from the database in a Laravel project.
License: MIT License
Auto-generates all Eloquent models from the database in a Laravel project.
License: MIT License
If I use it with the following command (taken from help: "models:generate [options] [--] []"):
php artisan models:generate table1,table2,table3...
it still will generate all tables from database.
Also this still will generate all tables:
php artisan models:generate --tables=table1,table2,table3...
Hi,
Firstly thank you, the code works very well, especially regarding foreign-key relations.
It would be very handy for us if we could add a prefix/suffix to class names, so that we can isolate and distinguish our repository-pattern classes from actual business logic classes.
For example, if we have an Order class, it would be good to have an OrderRepository class that Order extends, so that we can separate the repo from the business logic.
Thank you!
It should include by default the option of "SoftDelete" when it is automatically detected that the field "deleted_at"
hey @pepijnolivier
we should consider registering this generator to packagist.
and begin with tagging releases.
Would help!
Cheers Max
Method User11001\EloquentModelGenerator\Console\GenerateModelsCommand::handle() does not exist
Will this work with a 6 project?
When generating models it would be great to exclude the database prefix from the class names.
After running the following migration, I get an invalid model generated.
I suggest the issue is in the looping logic in User11001\EloquentModelGenerator\Console\GenerateModelsCommand::addManyToManyRules()
Migration
`
Schema::create('boma_coa_categories', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
$table->softDeletes();
});
Schema::create('boma_coa_codes', function(Blueprint $table)
{
$table->increments('id');
$table->string('boma_account_code');
$table->string('boma_account_name');
$table->text('description');
$table->string('boma_usage_type');
$table->string('boma_account_header_code');
$table->string('boma_account_header_name');
$table->integer('parent_boma_coa_code_id')->unsigned();
$table->integer('boma_coa_category_id')->unsigned();
$table->string('boma_sorting');
$table->string('boma_data_source');
$table->string('version_num');
$table->string('data_source');
$table->timestamps();
$table->softDeletes();
});
Schema::table('boma_coa_codes', function (Blueprint $table) {
$table->foreign('boma_coa_category_id')->references('id')->on('boma_coa_categories');
$table->foreign('parent_boma_coa_code_id')->references('id')->on('boma_coa_codes');
});`
How I generate Models
php artisan models:generate --path="app/Models/ModelsBase" --overwrite --namespace="App\Models\ModelsBase"
Resulting model class
`<?php namespace App\Models\ModelsBase;
use Illuminate\Database\Eloquent\Model;
class BomaCoaCategory extends Model {
/**
* Generated
*/
protected $table = 'boma_coa_categories';
protected $fillable = ['id', 'name', 'description', 'deleted_at'];
public function bomaCoaCodes() {
return $this->belongsToMany(\App\Models\ModelsBase\BomaCoaCode::class, 'boma_coa_codes', 'boma_coa_category_id', 'parent_boma_coa_code_id');
}
// SHOULD BE
// public function bomaCoaCategory() {
// return $this->hasMany(\App\Models\ModelsBase\BomaCoaCategory::class, 'boma_coa_category_id', 'id');
//}
public function bomaCoaCodes() {
return $this->hasMany(\App\Models\ModelsBase\BomaCoaCode::class, 'boma_coa_category_id', 'id');
}
}`
Hello,
I've run across a slight issue when using your otherwise very useful library.
When a user can specify the path for the location of the files to be created, using the APP_NAME or default App\Models namespace doesn't seem flexible enough to comply with PSR-4.
Could namespace be added as an option, so that a user can explicitly specify the model namespace and path when creating them?
Thanks.
Hi,
After I generate, name method was dublicate
ex:
public function affiliateCustomerInvites() {
return $this->hasMany(\App\Models\AffiliateCustomerInvite::class, 'customer_id', 'id');
}
public function affiliateCustomerInvites() {
return $this->hasMany(\App\Models\AffiliateCustomerInvite::class, 'inviter_id', 'id');
}
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.