Appearance
Relationships
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.
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.
sh
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.
sh
{
"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