FK input

The abbreviation FK refers to Foreign Key in GreenLight, just like in any database-related topic. An FK input handles 1:1 relationships with simple drop-down select inputs.

The 1:1 relationships handled by the FK input type have to be set up properly according to the Laravel specs. GreenLight uses Reliese to generate models, which means, most likely these relationships are already going to be implemented in your models.

Parameters
Parameter name Description
model Class name of the model connected to the current one
Important

There are known issues to consider while using FK Inputs:

  1. Model property casts that Reliese generates on models might cause problems while rendering in list views, so it is recommended to remove them, GreenLight handles values correctly anyway even if an FK value is not set
  2. Right now the FK input has no titleField parameter, which means, it always uses the "title" field of the related model to populate the drop-down input in the form views

These problems are expected to be fixed in a further release of GreenLight.

Example

Let's say you need a system that you can build a blog with. If you have no special needs, you might want to use the article system GreenLight supports. The Article model has two 1:1 relationships, but let's ignore the user_id field as we only want to handle the category of an article in an admin page.

FK sample

GreenLight's Article model has the following FK field configured in vendor/greenroom/greenlight/src/Resources/forms/article.yaml to handle the relationship between Article and ArticleCategory:

article_category_id:
    type: fk
    name: Kategória
    parameters: { model: ArticleCategory }