joligoms / nova-sort-relations
此包增强了Laravel Nova中关系排序的支持。
1.0.0
2021-11-17 13:17 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2024-09-17 20:09:49 UTC
README
此包增强了Laravel Nova中关系排序的支持。
安装
通过composer安装
$ composer require joligoms/nova-sort-relations
使用
将Joligoms\SortRelations\SortRelations
trait包含到你的资源类中,或者如果你希望所有资源都拥有此功能,可以在App\Nova\Resource
中包含。在$sortRelations
数组中定义可排序的列。
... use Joligoms\SortRelations\SortRelations; ... class Post extends Resource { public static $sortRelations = [ 'user' => /* The attribute specified in the field, for example: ˅˅˅˅ Text::make(__('User'), 'user', function () { return $this->model()->user->username; }); */ [ 'relation' => 'user', // The relation from the current resource's model. 'title' => 'username', // (Optional) The relation's column that should be selected in the indexQuery. If not specified, it will use the resource's title property. 'columns' => 'username' // The columns that should be ordered in the query. It can be a string or array. ], 'company' => [ 'relation' => 'user.company', // Dot notation can be specified when the relation goes through multiple relations. 'columns' => 'name' ] ]; public static function indexQuery(NovaRequest $request, $query) { // You can modify your base query here, only if necessary. Sort Relations will be applied automatically... return $query; } }
安全
如果你发现任何与安全相关的问题,请通过电子邮件联系作者而不是使用问题跟踪器。
致谢
许可
MIT许可证。有关更多信息,请参阅许可文件。