在Dcat Admin中实现分类表单无限极select下拉框选中代码示例
Laravel  /  管理员 发布于 2个月前   271
在Dcat Admin表单中实现分类下拉框筛选无极限功能
GoodsCategory代码:
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Dcat\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class GoodsCategory extends Model
{
use ModelTree; //必须
use HasDateTimeFormatter;
use SoftDeletes;
protected $titleColumn = 'name'; //如果表中分类名称字段名不是‘title’
protected $orderColumn = 'sorts'; //如果表中排序字段名不是‘order’
public static function getAll ()
{
return self::where('status', 1)->whereNull('deleted_at')->latest('sorts')->get(['id', 'name', 'parent_id']);
}
public static function selectOptions(\Closure $closure = null)
{
$options = (new static())->withQuery($closure)->buildSelectOptions();
return collect($options)->all();
}
}
GoodsController中使用:
//表单中
$form->select('category_id')
->options(GoodsCategory::selectOptions())
->saving(function ($v) {
return (int) $v;
})->required();
//筛选器中
$filter->equal('category_id')->select(function () {
return GoodsCategory::selectOptions();
});
效果:
路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..博主 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 @ mashrdn 多切换几个节点测试,免费ssr是没那么稳..mashrdn 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 V2rayn免费节点添加上去了,youtobe无法打开网页,是怎么回事..张伟 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 3q!有用,不过免费节点隔天就要去git上复制新的导进去..博主 在
科学上网翻墙访问Google , 上外网神器佛跳墙VPN(永久免费)使用流程步骤中评论 该篇教程已不能用了,告知大家,免的老有老铁问我!..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号