jinn/laravel is a Laravel package for jinn for laravel. models, migrations and api generator..
It currently has 8 GitHub stars and 37 downloads on Packagist (latest version v0.2.1).
Install it with composer require jinn/laravel.
Discover more Laravel packages by jinn
or browse all Laravel packages to compare alternatives.
Last updated
Jinn is a code generator that speeds up your work by generating Models, Migrations, and APIs from simple YAML-based definitions. What makes Jinn different from other generators is that it lets you customize the generated code without losing the ability to update it when definitions change.
Read full documentation at jinncode.dev.
Of course, there are plenty of frameworks and libraries which serve the same purposes using various approaches. This section describes key design decisions which make Jinn different.
Unlike many API and admin panel frameworks, Jinn uses code generation, as it gives the following benefits:
update method in your
API, it will not be generated at all.Symfony and Laravel frameworks also use code generation. However, they apply caching approach, i.e., generate the code at runtime. Jinn generates the code at build-time, which means that there are no first-run performance drawbacks and lets you inspect the code easily.
All the above means that:
Each class generated by Jinn (except for Migrations) is split into two files:
The idea is borrowed from Propel, a well-known in the past PHP ORM. The main class is
generated only once and never updated, so you can use it to customize generated logic freely.
At the same Jinn can update the base class logic for you whenever the definition changes.
Currently, Jinn supports SQL databases only. MongoDB support is planned.
Jinn is designed to manage its database tables and models, i.e., it is not able to work with existing models and database tables. It also expects that no changes will be made to its database tables; otherwise, they may be overwritten. At the same time, it is possible to have Jinn-managed and non-Jinn-managed tables in the same database.
The Jinn reference implementation is made for Laravel, but it is designed to allow implementation for any framework. Contributors are welcome.
Further down this guide, the sections which are specific to Laravel will be marked correspondingly.
composer require jinn/jinn-laravel@dev-master
php artisan vendor:publish --provider="Jinn\Laravel\JinnServiceProvider"
Default structure:
jinn
def
gen
An alternative structure can be configured via config/jinn.php.
Further, this guide will use a default configuration. Changing the Jinn configuration
should result in corresponding changes to the next steps.
Edit composer.json, locate autoload section, and add a line as follows:
"autoload": {
"psr-4": {
...
"JinnGenerated\\": "jinn/gen/"
}
}
Then ask the composer to update autoload files:
composer dump-autoload
Copy the following definition into jinn/def/entities.yaml or create your own.
User:
class:
extends: Illuminate\Foundation\Auth\User
properties:
name: string
email: { type: string, unique: true }
password: string
avatar_filename: { type: string, required: false }
Post:
properties:
content: text
author: { entity: User, relation: many-to-one }
published_at: datetime
comments: { entity: Comment, relation: one-to-many }
Comment:
properties:
content: text
author: { entity: User, relation: many-to-one }
published_at: datetime
Ask Jinn to generate the files
php artisan jinn
Inspect generated files under app and jinn/gen folders.
id