islamdb / orchid-helper
Orchid平台助手
Requires
- orchid/crud: ^3.0
- orchid/platform: ^10.0|^11.0|^12.0
This package is auto-updated.
Last update: 2024-09-30 01:52:11 UTC
README
Orchid Helper 提供了许多类和特性,可以帮助你在开发中节省大量时间
安装
本手册假设你已经安装了 Laravel 和 Orchid
你可以使用 Composer 安装此包。在命令行中运行以下命令:
composer require islamdb/orchid-helper
这将更新 composer.json
并将包安装到 vendor/
目录中。
特性
ResourceDefaultAllowedSortsAndFilters
此特性会将 $allowedSorts
和 $allowedFilters
填充。依赖于你的 Model 中的 $fillable
用法
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefaultAllowedSortsAndFilters; class YourModel extends Model { use ResourceDefaultAllowedSortsAndFilters; ... }
ResourceDefaultFilter
此特性将使资源默认排序
用法
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefaultFilter; class YourResource extends Resource { use ResourceDefaultFilter; ... }
你可以在 构造函数 中更改 $defaultSortedColumn
和 $defaultSortedOrder
ResourceDefaultLabel
此特性将更改资源名称的默认标签
用法
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefaultLabel; class YourResource extends Resource { use ResourceDefaultLabel; ... }
这将从 "Your Resource" 变为 "Your"。但你可以通过在构造函数中更改 static $labelToReplace
的值来修改
ResourceDefaultSortingByFilename
此特性将按文件名排序资源
用法
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefaultSortingByFilename; class YourResource extends Resource { use ResourceDefaultSortingByFilename; ... }
ResourceDeleteAction
此特性将提供默认的删除操作
用法
use IslamDB\OrchidHelper\Resource\Traits\ResourceDeleteAction; class YourResource extends Resource { use ResourceDeleteAction; ... }
ResourceOnSave
此特性将帮助你保存资源中的附件和可生成缩略图的字段
用法
use IslamDB\OrchidHelper\Resource\Traits\ResourceOnSave; class PostResource extends Resource { use ResourceOnSave; public function onSave(ResourceRequest $request, Model $model) { $this->sluggable($request); $this->saveWithAttachment($request, $model); } ... }
ResourceDefault
所有之前的特性都包含在此特性中
用法
use IslamDB\OrchidHelper\Resource\Traits\ResourceDefault; class YourResource extends Resource { use ResourceDefault; ... }
字段
此类由 Orchid 设置包使用。你可以访问 islamdb/orchid-setting
输入类型
Field::INPUT_EMAIL // 'email' Field::INPUT_FILE // 'file' Field::INPUT_HIDDEN // 'hidden' Field::INPUT_MONTH // 'month' Field::INPUT_NUMBER // 'number' Field::INPUT_PASSWORD // 'password' Field::INPUT_RADIO // 'radio' Field::INPUT_RANGE // 'range' Field::INPUT_SEARCH // 'search' Field::INPUT_TEL // 'tel' Field::INPUT_TEXT // 'text' Field::INPUT_TIME // 'time' Field::INPUT_URL // 'url' Field::INPUT_WEEK // 'week'
必需方法
\IslamDB\OrchidHelper\Field::REQUIRED_METHODS
值
[ RadioButtons::class => [ 'options' => "['one' => 'One', 'two' => 'Two', 'three' => 'Three']" ], Range::class => [ 'min' => "1", 'max' => "100", 'step' => "1" ], Select::class => [ 'options' => "['one' => 'One', 'two' => 'Two', 'three' => 'Three']" ], Picture::class => [ 'targetId' => '' ] ]
带元数据
返回带有字段参数的元字段
// function public static function withMeta(array $fields) // usage \IslamDB\OrchidHelper\Field::withMeta([ View::make('group'), View::make('slug'), Input::make('title'), View::make('body'), View::dateTime('published_at'), View::dateTime('expired_at') ])
检查文件字段
检查类型是否为文件字段
// function public static function isFileField($type) // usage \IslamDB\OrchidHelper\Field::isFileField(\Orchid\Screen\Fields\Input::class) // false
获取所有字段
获取所有可用的 Orchid 字段
// function public static function all(bool $withMethods = true, $typeClass = null) // usage \IslamDB\OrchidHelper\Field::all()
查找字段
通过类名查找字段并返回方法等
// function public static function find($type, bool $withMethods = true) // usage \IslamDB\OrchidHelper\Field::find(\Orchid\Screen\Fields\Matrix::class)
生成字段
通过类名生成字段,带有选项(Orchid 设置)
public static function make($type, string $name = 'value', array $options = [])
列
用法
use IslamDB\OrchidHelper\Column;
制作
此函数将帮助你创建具有默认标题、排序和筛选功能的列
public static function make($name, $title = null, bool $sorting = true, $filter = TD::FILTER_TEXT)
示例
Column::make('full_name')
输出
(column with "Full Name" column name and filter)
URL
使用此函数生成 URL 表列
public static function url(string $name, string $title = null, $target = '_blank')
示例
Column::url('social_media_url', null, null) Column::url('social_media_url', null, '_blank')
输出
1. (clickable and go to address in current tab) 2. (clickable and go to address in new tab)
HTML
此函数将帮助你打印 HTML
public static function html(string $name, string $title = null)
示例
Column::html('body')
输出
粗体文本
<b><i>Bold Text</i></b>
关系
此函数将帮助你打印关系字段
public static function relation(string $name, string $title = null, $columns = 'name', string $glue = ', ', string $glueColumn = ' ')
示例
假设你想要获取具有其角色(超级管理员和管理员)的用户
Column::relation('roles', null, ['name', 'slug'], ', ', ' - ')
输出
Super Admin - super-admin, Administrator - administrator
布尔值
此函数将帮助你打印布尔值
public static function boolean($name, $title = null, array $labels = null)
示例
Column::boolean('enabled', 'Is Active', [true => 'Yes', false => 'No'])
输出
Yes/No (depand on your value)
日期时间
此函数将帮助你打印 datetime/timestamp
public static function dateTime($name, $title = null, string $locale = 'id', $withTime = true, $withDayName = true)
示例
Column::dateTime('updated_at', 'Last Edit', 'en', true, true)
输出
Tuesday, August 31st 2021, 09:05:38 (depand on your value)
金钱/数字
此函数将帮助你打印数字/金钱值
public static function money($name, $title = null, $decimals = 2, $zeroTrail = true, $decimalSeparator = '.', $thousandSeparator = ',')
示例
1. Column::make('total', null, 4, true) 2. Column::make('total', null, 4, false)
输出
1. 250,000.23 2. 250,000.2300
快捷方式
此函数将帮助你查看/编辑资源
public static function shortcut($name, $title = null, string $route = 'platform.resource.view', int $deep = 2)
示例
1. Column::shortcut('name', null, 'platform.resource.view') 2. Column::shortcut('name', null, 'platform.resource.edit')
输出
1. (clickable, and go to view page) 2. (clickable, and go to edit page)
查看
用法
use IslamDB\OrchidHelper\View;
制作
此函数将帮助你创建具有默认标题的视图
public static function make(string $name, string $title = null)
示例
View::make('full_name')
输出
(view with "Full Name")
URL
使用此函数在视图页中生成 URL
public static function url(string $name, string $title = null, string $target = '_blank')
示例
1. View::url('social_media_url', null, null) 2. View::url('social_media_url', null, '_blank')
输出
1. (clickable and go to address in current tab) 2. (clickable and go to address in new tab)
HTML
此函数将帮助你打印 HTML
public static function html(string $name, string $title = null)
示例
View::html('body')
输出
粗体文本
<b><i>Bold Text</i></b>
关系
此函数将帮助你打印关系字段
public static function relation(string $name, string $title = null, $columns = 'name', string $glue = ', ', string $glueColumn = ' ')
示例
View::relation('roles', null, ['name', 'slug'], ', ', ' - ')
输出
Super Admin - super-admin, Administrator - administrator
布尔值
此函数将帮助你打印布尔值
public static function boolean($name, $title = null, array $labels = null)
示例
View::boolean('enabled', 'Is Active', [true => 'Yes', false => 'No'])
输出
Yes/No (depand on your value)
日期时间
此函数将帮助你打印 datetime/timestamp
public static function dateTime($name, $title = null, string $locale = 'id', $withTime = true, $withDayName = true)
示例
View::dateTime('updated_at', 'Last Edit', 'en', true, true)
输出
Tuesday, August 31st 2021, 09:05:38 (depand on your value)
金钱/数字
此函数将帮助你打印数字/金钱值
public static function money($name, $title = null, int $decimals = 2, bool $zeroTrail = true, string $decimalSeparator = '.', string $thousandSeparator = ',')
示例
假设总金额 = 250000.23
1. View::make('total', null, 4, true) 2. View::make('total', null, 4, false)
输出
1. 250,000.23 2. 250,000.2300
元视图
返回元视图
public static function meta(): array { return [ static::make('meta_title'), static::make('meta_keywords'), static::make('meta_description') ]; }
时间戳视图
返回时间戳视图
public static function timestamps(): array { return [ static::dateTime('created_at'), static::dateTime('updated_at') ]; }
带元数据视图
返回带有数组视图参数的元视图
public static function withMeta(array $views): array { return array_merge($views, static::meta()); }
带时间戳
返回带有数组时间戳参数的视图
public static function withTimestamps(array $views): array { return array_merge($views, static::timestamps()); }
带元数据和时间戳
返回带有数组参数的元时间戳视图
public static function withMetaAndTimestamps(array $view): array { return array_merge($view, static::meta(), static::timestamps()); }