laravel-backpack - 将父数据传递到与 laravel 背包中的嵌套资源关联的列表或 crud
问题描述
我正在使用本教程https://backpackforlaravel.com/articles/tutorials/nested-resources-in-backpack-crud 在背包中设置嵌套资源。我意识到我可以自定义视图
$this->crud->setListView('my-view-name');
但我想知道如何将其他数据传递到此视图中。我想传递父资源,以便我可以说类似
Posts for {{$parent_resource->title}}
在列表(索引)视图的顶部。
所以我想我想知道是否有任何方法可以将父资源模型传递给列表和 crud 视图?
解决方案
您应该能够编写类似的东西Posts for {{ $parent_resource->title }}
,但是从嵌套控制器,而不是视图。
在 Backpack 3.5 中,您可以使用以下方法更改操作的标题和副标题:
$this->crud->setTitle('some string', 'create'); // set the Title for the create action
$this->crud->setHeading('some string', 'create'); // set the Heading for the create action
$this->crud->setSubheading('some string', 'create'); // set the Subheading for the create action
现在,ChildCrudController::setup()
您有请求,因此您可以:
- 从中获取父 ID
$this->crud->request
; - 从数据库中获取特定的父条目;
- 使用上述方法设置标题(浏览器标题栏)、标题(页面上最大的文本)或副标题(页面上第二大文本,紧挨标题)的文本;
希望能帮助到你。干杯!
推荐阅读
- android - Android P2P 直接连接多个设备。同时作为 GroupOwner 和客户对等
- javascript - 如何在 React Native 中停止这些并发动画?
- javascript - 如何根据用户时区更改时间戳?
- elasticsearch - 查询子属性
- ruby-on-rails - Rails 6 + Webpacker 4 + PostCSS & @font-face + 本地字体
- perl - 如何重命名目录中的所有文件以具有相同数量的数字?
- sparql - Graphdb sparql 无法进行联合查询
- mysql - 需要将mysql转为SQL
- r - 如何将转换矩阵读入 Cytoscape 以进行马尔可夫链建模?
- reactjs - 我可以为 ReactJS 重新使用相同的 onload.js 函数吗