Download the PHP package laracademy/generators without Composer
On this page you can find all versions of the php package laracademy/generators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laracademy/generators
More information about laracademy/generators
Files in laracademy/generators
Package generators
Short Description This package will generate a Laravel Model based on your database table itself, filling in the required fields automatically.
License MIT
Informations about the package generators
Laracademy Generators
Laracademy Generators - is a tool set that helps speed up the development process of a Laravel application.
Author(s):
Requirements
- PHP 7.4+
- Laravel 6.*
- MySQL *
* For Laravel 5. please use the version 1.5
Usage
Step 1: Install through Composer
Step 2: Artisan Command
Now that we have added the generator to our project the last thing to do is run Laravel's Arisan command
You will see the following in the list
Commands
generate:modelfromtable
This command will read your database table and generate a model based on that table structure. The fillable fields, casts, dates and even namespacing will be filled in automatically.
You can use this command to generate a single table, multiple tables or all of your tables at once.
This command comes with a bunch of different options, please see below for each parameter
- --table=
- This parameter if filled in will generate a model for the given table
- You can also pass in a list of tables using comma separated values
- When omitted, all tables will generate a model
- In this scenario you can optionally specify a whitelist/blacklist in
config/modelfromtable.php
migrations
table will be blacklisted by default
- --connection=
- By default, if omitted, the default connection found in
config/database.php
will be used - To specify a connection, first ensure that it exists in your
config/database.php
- By default, if omitted, the default connection found in
- --folder=
- By default, all models are store in your app/ directory. If you wish to store them in another place you can provide the relative path from your base laravel application.
- Alternatively, use a lambda in
config/modelfromtable.php
to dynamically specify folder path
- --namespace=
- By default, all models will have the namespace of
App\Models
- Alternatively, use a lambda in
config/modelfromtable.php
to dynamically specify namespace
- By default, all models will have the namespace of
- --debug=[true|false (default)]
- Shows some more information while running
- --singular=[true|false (default)]
- This will create a singular titled model, e.g. "Categories" -> "Category"
- --overwrite=[true|false (default)]
- Overwrite model file(s) if exists
- --timestamps=[true|false (default)]
- whether to timestamp or not
Examples (CLI)
Generating a single table
Generating a multiple tables
Changing to another connection found in database.php
Changing the folder where to /app/Models
Configuration file for saving defaults, dynamic lambdas
A config file should be in your project's config folder (if not, you can easily create it). Through this, you can set defaults you commonly use to cut down on the input your command line call requires. Some fields, like namespace
, accept a static value or, more powerfully, a lambda to generate dynamic values. Additional fields not available to the CLI are available in the config. See below.
Whitelist/Blacklist (config only)
Particularly large databases often have a number of tables that aren't meant to have models. These can easily be filtered through either the whitelist or blacklist (or both!). Laravel's "migrations" table is already included in the blacklist. One nice feature is that you can wildcard table names if that makes sense for your situation...
Filename, using lambda
Large databases sometimes use a pattern of prefixing for organization, which you can use to organize your model files through a lambda.
In this example, 'system_user' would generate the filename 'User'. Note that this is also available through the CLI, but it probably doesn't make as much sense to set there.
Folder path, using lambda
Using the last example, you can also organize the folder path using the prefix...
In this example, 'system_user' would generate the folder path 'path/to/your/install/app/Models/System'
Namespace, using lambda
Using the last example, you would want to then generate a matching namespace to the file path
Therefore the folder path 'path/to/your/install/app/Models/System' would generate the namespace 'App\Models\System'
Delimiter (config only)
By default array values are delimited with a simple comma, but a common preference is to delimit with a newline as well.
Result:
License
ModelGen is open-sourced software licensed under the MIT license
Bug Reporting and Feature Requests
Please add as many details as possible regarding submission of issues and feature requests
Disclaimer
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 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.