Skip to content

Commit

Permalink
Merge pull request #19 from pepijnolivier/v2
Browse files Browse the repository at this point in the history
feature/v3
  • Loading branch information
pepijnolivier authored Jun 1, 2023
2 parents a9930e0 + 70d7a87 commit 0b12e91
Show file tree
Hide file tree
Showing 34 changed files with 1,311 additions and 752 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
19 changes: 19 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/art export-ignore
/docs export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.php_cs.dist.php export-ignore
/psalm.xml export-ignore
/psalm.xml.dist export-ignore
/testbench.yaml export-ignore
/UPGRADING.md export-ignore
/phpstan.neon.dist export-ignore
/phpstan-baseline.neon export-ignore
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
.idea
.phpunit.cache
build
composer.lock
coverage
docs
phpunit.xml
phpstan.neon
testbench.yaml
vendor
node_modules
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Open to PR's
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) <Taylor Otwell>
Copyright (c) pepijnolivier <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
117 changes: 73 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,99 @@
# Eloquent-Model-Generator for Laravel 5
Auto-generates all Eloquent models from the database in a Laravel 5 project.
This will also add all relation functions to your generated models (belongsTo, belongsToMany, hasMany, hasOne).
# Eloquent Model Generator

> I'm also creating a ServiceProvider that will auto-generate basic CRUD functionality for these models. For now, you can use [Laravel Administrator](https://github.com/FrozenNode/Laravel-Administrator) or [Dick Crud](https://github.com/tabacitu/crud) for this task. You should also look at [Laravel API Generator](https://github.com/mitulgolakiya/laravel-api-generator)

##Installation
[![Latest Version on Packagist](https://img.shields.io/packagist/v/pepijnolivier/eloquent-model-generator.svg?style=flat-square)](https://packagist.org/packages/pepijnolivier/eloquent-model-generator)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/pepijnolivier/eloquent-model-generator/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/pepijnolivier/eloquent-model-generator/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/pepijnolivier/eloquent-model-generator/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/pepijnolivier/eloquent-model-generator/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/pepijnolivier/eloquent-model-generator.svg?style=flat-square)](https://packagist.org/packages/pepijnolivier/eloquent-model-generator)

Add the following packages to your `composer.json`

```
"require-dev": {
"xethron/migrations-generator": "dev-l5",
"way/generators": "dev-feature/laravel-five-stable",
"user11001/eloquent-model-generator": "~2.0"
}
```

Notice: Laravel 5.0 users should use `"user11001/eloquent-model-generator": "~1.0"`, since 2.0 this package uses the 'modern' relationship notation
This package will generate models with their appropriate Eloquent relations based on an existing database.

For automatically generating migrations, see [kitloong/laravel-migrations-generator](https://github.com/kitloong/laravel-migrations-generator)

You also need to point to the fork of the way/generators repo. See [Xethron/migrations-generator](https://github.com/Xethron/migrations-generator) for more info about this.

```
"repositories": [
{
"type": "git",
"url": "[email protected]:jamisonvalenta/Laravel-4-Generators.git"
}
]
```
## Installation

You can install the package via composer:

Next, run `composer update`
```bash
composer require pepijnolivier/eloquent-model-generator
```

You can publish the config file with:

Next, add the following service providers to your `config/app.php`
```bash
php artisan vendor:publish --tag="eloquent-model-generator-config"
```
'Way\Generators\GeneratorsServiceProvider',
'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
'User11001\EloquentModelGenerator\EloquentModelGeneratorProvider',

This is the contents of the published config file:

```php
<?php

use Illuminate\Database\Eloquent\Model;

return [
/*
|--------------------------------------------------------------------------
| Namespace
|--------------------------------------------------------------------------
|
| The default namespace for generated models.
|
*/
'model_namespace' => 'App\Models\Generated',
'trait_namespace' => 'App\Models\Generated\Relations',

/*
|--------------------------------------------------------------------------
| Output Path
|--------------------------------------------------------------------------
|
| Path where the models will be created.
|
*/
'model_path' => 'app/Models/Generated',
'trait_path' => 'app/Models/Generated/Relations',

/*
|--------------------------------------------------------------------------
| Extend Model
|--------------------------------------------------------------------------
|
| Extend the base model.
|
*/
'extend' => Model::class,
];

```

Lastly, make sure your `.env` file has correct database information

##Usage
## Usage

**Default: generate all models into the default folder**
> `php artisan models:generate`
```php
php artisan generate:models
```

**Specify path where to generate to**
> `php artisan models:generate --path="app/Models"`
## Testing

**Specify the namespace of the models**
> `php artisan models:generate --namespace="User11001/Models"`
```bash
composer test
```

**Overwrite existing models**
> `php artisan models:generate --overwrite`
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security Vulnerabilities

##Example
See mysql workbench schema `example.mwb` and `example.sql` in `/example`
Please see [SECURITY](SECURITY.md) for details.

##Contributors and Pull Requests
Please contribute and help enhance this package. All pull requests will be revised quickly.
Please use the development branch for pull requests.
## Credits

<a href="https://rollbar.com"><img src="https://d26gfdfi90p7cf.cloudfront.net/rollbar-badge.144534.o.png" alt=“Rollbar Error Tracking /></a>
- [Pepijn Olivier](https://github.com/pepijnolivier)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Just open an issue
12 changes: 12 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- timestamps
- softdeletes
- specify database
- detect hasManyThrough etc (see other generator packages for that ?)
- morph (...type + ...id)
- belongsToThrough (hoeveel levels diep ?) ~> alles !
- hasManyThrough (hoeveel levels diep ?) 1,2, 3, 4 of 5 excluding pivots
=> theorie: zal mogelijk conflicting relation names geven dus moet de laatste zijn om te implementeren
=> https://stackoverflow.com/questions/21699050/many-to-many-relationships-in-laravel-belongstomany-vs-hasmanythrough
- config automatically excludes tables to proces (migrations, etc)
- consider relations less verbose if automatically detectable via column names

82 changes: 61 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,75 @@
{
"name": "user11001/eloquent-model-generator",
"description": "Auto-generates all Eloquent models from the database in a Laravel 5 project.",
"keywords": ["laravel", "model", "eloquent", "artisan"],
"name": "pepijnolivier/eloquent-model-generator",
"description": "Eloquent Model Generator",
"keywords": [
"pepijnolivier",
"laravel",
"eloquent-model-generator"
],
"homepage": "https://github.com/pepijnolivier/eloquent-model-generator",
"license": "MIT",
"minimum-stability": "dev",
"authors": [
{
"name": "Pepijn Olivier",
"email": "[email protected]"
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": ">=4.1",
"xethron/migrations-generator": "*"
"php": "^8.1",
"illuminate/contracts": "^10.0",
"illuminate/support": "^10.13",
"kitloong/laravel-migrations-generator": "^6.10",
"nette/php-generator": "^4.0",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "~7",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-arch": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0"
},
"repositories": [
{
"type": "git",
"url": "[email protected]:jamisonvalenta/Laravel-4-Generators.git"
}
],
"autoload": {
"psr-4": {
"User11001\\EloquentModelGenerator\\": "src/"
"Pepijnolivier\\EloquentModelGenerator\\": "src/",
"Pepijnolivier\\EloquentModelGenerator\\Database\\Factories\\": "database/factories/"
}
},
"require-dev": {
"phpunit/phpunit": ">=4.0.0",
"mockery/mockery": ">=0.9.0",
"illuminate/cache": ">=4.1.0",
"illuminate/console": ">=4.1.0"
}
"autoload-dev": {
"psr-4": {
"Pepijnolivier\\EloquentModelGenerator\\Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"providers": [
"Pepijnolivier\\EloquentModelGenerator\\EloquentModelGeneratorServiceProvider"
],
"aliases": {
"EloquentModelGenerator": "Pepijnolivier\\EloquentModelGenerator\\Facades\\EloquentModelGenerator"
}
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
37 changes: 37 additions & 0 deletions config/eloquent-model-generator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Eloquent\Model;

return [
/*
|--------------------------------------------------------------------------
| Namespace
|--------------------------------------------------------------------------
|
| The default namespace for generated models.
|
*/
'model_namespace' => 'App\Models\Generated',
'trait_namespace' => 'App\Models\Generated\Relations',

/*
|--------------------------------------------------------------------------
| Output Path
|--------------------------------------------------------------------------
|
| Path where the models will be created.
|
*/
'model_path' => 'app/Models/Generated',
'trait_path' => 'app/Models/Generated/Relations',

/*
|--------------------------------------------------------------------------
| Extend Model
|--------------------------------------------------------------------------
|
| Extend the base model.
|
*/
'extend' => Model::class,
];
Empty file added phpstan-baseline.neon
Empty file.
14 changes: 14 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
includes:
- phpstan-baseline.neon

parameters:
level: 4
paths:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false

Loading

0 comments on commit 0b12e91

Please sign in to comment.