Download the PHP package mojopollo/laravel-json-schema without Composer
On this page you can find all versions of the php package mojopollo/laravel-json-schema. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mojopollo/laravel-json-schema
More information about mojopollo/laravel-json-schema
Files in mojopollo/laravel-json-schema
Package laravel-json-schema
Short Description Create all your migrations and models from one JSON schema file. Laravel Database Schema in JSON allows you to define your entire Laravel database schema in one JSON file then generates all the necessary migration files
License MIT
Homepage http://localhost
Informations about the package laravel-json-schema
JSON database schema for Laravel
Create all your migrations and models from one JSON schema file. This package allows you to define your entire Laravel database schema in one JSON file then generates all the necessary migration files. Makes use of Jeffrey Way's Extended Generators.
- Versions
- Installation
- Usage
- Create your schema in JSON
- Generate your migrations
- Pivot tables
- Undo
- Validation
- JSON File Examples
Versions
For Laravel 5.4.x and above use laravel-json-schema tag 5.4.x. You might need to set your composer.json minimum-stability to dev
:
For Laravel 5.3.x and below use laravel-json-schema tag 1.x.x
Installation
Step 1: Add package via composer
Add this package to your composer.json
file with the following command
Step 2: Add the service providers
Add the following 2 service providers to your local environment only, by modifying your as so:
Usage
Create your schema in JSON
Create your JSON schema file and save as for example:
Generate your migrations
If you have your JSON file, you can now generate all your migrations, using the option to specify where the JSON file is located:
After this command executes you will see all the newly created migration files, example output:
If you have a extensive long schema json file and want to only generate specific tables or migrations from the schema, you would do the following:
In the above example, the tables or migrations named "categories" and "tags" will be generated and all other tables/migrations will be ignored.
Pivot tables
If you need to generate a pivot table, you will append to your migration name, for example:
This will create a pivot table migration for the tables and
Undo
To undo and delete all files that where previously generated with the json file that was used, example:
What this will do is look for the file if it exists, read the contents and remove all files that where generated, example output:
If you prefer not to create a "undo file" in the same directory as the source json file, use the option at the time of migration generation:
This will prevent the creation of a undo file.
Validation
To check your json file for valid json syntax and schema validation (column type definitions and column type modifiers checks):
Note: this does not generate any migration files and will just check if you misspelled any field schema definitions
JSON File Examples
Using table names or migration names
You can use table names or use a migration name that Extended Generators will understand.
For example:
Is the same as:
Putting it all together
You can now get crazy with defining your entire database schema and having the benefit of seeing it all in one file. As you have seen we can to remove all previously generated files from the last command then make edits to our JSON file, validate the syntax with and then generate it all over again. One word: WOW. :)
All versions of laravel-json-schema with dependencies
illuminate/support Version ~5.0
illuminate/filesystem Version ~5.0
illuminate/database Version ~5.0
laracasts/generators Version dev-master#4e9ce5db9d93475ca27b993a92de3b15090aa139