entries - 链接到其他条目通过 UUID 或句柄。
author:
label: Author
type: entries
source: <uuid|handle>以下属性受支持。
| 属性 | 说明 |
|---|---|
| source | 关联蓝图的 UUID 或句柄名。 |
| maxItems | 限制可选择的条目数量。 |
| displayMode | 修改字段的显示方式。支持的值包括:relation、recordfinder、taglist、controller。默认值为 relation。 |
| conditions | 指定应用于模型查询的原始 where 查询语句。 |
| modelScope | 应用于关联表单模型的模型查询作用域方法,可以是模型方法名,也可以是静态 PHP 类方法(如 Class::method)。 |
| inverse | 当定义为反向关系时,设置源蓝图中关联字段的名称。 |
要限制可选项目的数量,使用 maxItems 属性。
author:
type: entries
maxItems: 1要显示记录查找器而不是典型的控件, 请使用 displayMode 属性. 此模式仅在只有一个项目可选择时可用.
author:
type: entries
displayMode: recordfinder当有多个项目可用时,displayMode 支持使用标签列表选择项目。
author:
type: entries
displayMode: taglist您可以使用以下方法,通过 SQL 或 PHP 限制相关查询。在示例中,相关记录有一个名为 is_featured 的字段,它渲染为复选框。我们可以将相关记录限制为仅勾选了此复选框的记录。
您可以使用原始 SQL 查询,通过 conditions 属性来限制相关的模型。
categories:
label: Categories
type: entries
source: Blog\Category
conditions: is_featured = true你可以使用一个PHP方法并结合scope属性来限制相关查询。
basic_entries:
label: Basic Entry
type: entries
source: Basic\Entry
scope: App\Classes\ScopeHelper::applyScope这将指代 App\Classes\ScopeHelper 类,该文件可能位于 app/classes/ScopeHelper.php,例如。
namespace App\Classes;
class ScopeHelper
{
public static function applyScope($query)
{
return $query->where('is_featured', true);
}
}在某些情况下,你可能希望反向访问这种关系,例如查找属于某个特定类别的所有文章。inverse 属性可用于反向链接这种关系,其中属性值被设置为源蓝图中的字段名。
例如,如果一个 Blog\Post 蓝图已经定义了一个 categories 关系。
categories:
type: entries
source: Blog\CategoryBlog\Category 蓝图可以包含一个 posts 字段作为源蓝图(上方)中 categories 字段的 inverse. 该字段可以通过将 hidden 值设置为 true, 并且这是可选的.
posts:
type: entries
source: Blog\Post
inverse: categories
hidden: true默认情况下,entries 字段将显示为指向相关记录的超链接。
要显示列表列以显示相关记录的计数,您可以使用以下列配置。其中 relation 属性应设置为字段名称,并将 relationCount 设置为 true,以及 number 列类型。
categories:
label: Categories
type: entries
# ...
column:
relation: categories
relationCount: true
type: number若要在表单中创建、更新和删除项目,请将 displayMode 设置为 controller 以显示高级管理模式,由 关系控制器行为 提供支持。
author:
type: entries
displayMode: controller如果蓝图的 navigation 设置为 false 则默认按钮将显示 Create 和 Delete。如果定义了导航,则按钮显示 Add 和 Remove。您可以使用 toolbarButtons 属性自定义这些按钮。
author:
type: entries
toolbarButtons: create|add|remove|delete关系控制器中使用的各种消息取自源蓝图 customMessages,属性,并且你也可以使用字段定义上的 customMessages 来修改它们。
author:
type: entries
customMessages:
buttonCreate: New Author
titleUpdateForm: Update Author
titleCreateForm: Create Author