Relationships (Beta)
Work on relationships are also going on to support data insertion on relationships by forms and apis. As of now, generator is able to specify relationships in models via all three input methods. Console, File & Auto detect from table.
Getting Started
From Console
To get started with relationships from console, you need to specify --relations
option when
running artisan command. e.g.
php artisan infyom:api_scaffold Post --relations
When you specify relations option, it will ask you for third input for relations.
Enter relationship (Leave Blank to skip):
Relationship input is accepted as string with some pre-defined format. Here is the format for it:
relationship_type,model_name,field1,field2,field3
It's a same format which is accepted by laravel in Eloquent Model
You can specify relationship input as a string as specified in below table based on relationship type. Also you can skip it, if specified field doesn't have any relationship.
From File
To specify relationships when passing input from file, you can specify relationship with one more field as following example.
{
"name": "writer_id",
"dbType": "integer:unsigned:foreign,writers,id",
"htmlType": "text",
"relation": "mt1,Writer,writer_id,id"
},
You can specify relationship input as a string as specified below in this document based on relationships. Also you can skip it, if specified field doesn't have any relationship.
From Table
When using table input for fields, you don't need to specify any relationship data. Generator will try to auto detect foreign keys and will create relationships in functions in your models
Relationships Inputs
Relationship Type | Valid Examples |
---|---|
One to One |
1t1,Phone 1t1,Phone,user_id 1t1,Phone,user_id,id |
One to Many |
1tm,Comment 1tm,Comment,post_id 1tm,Comment,post_id,id |
Many to One |
mt1,Post mt1,Post,post_id |
Many to Many |
mtm,Role mtm,Role,user_roles mtm,Role,user_roles,user_id,role_id |