$grid->model()->select('id','name')->where('status',1)->groupBy('project_id');
$grid->model()->select('id','name')->where('status',1)->groupBy('project_id');
//结合having 查出名字重复的
$grid->model()->select('name_en')->groupBy('name_en')->havingRaw('count(name_en)>1')
//嵌套子查询 查出名字重复的全部信息
$grid->model()->select('id','name_en')->whereIn('name_en',Project::select('name_en')->groupBy('name_en')->havingRaw('count(name_en)>1'))->orderBy('name_en');
$grid->id('ID')->sortable();
$grid->name_cn('名称');
注:name_cn为与数据库对应的字段名
$grid->column('name_cn','名称');
$grid->column('type','类型?')->display(function ($type) {
return $type == 1 ? '111' : '222';
});
$grid->model()->where('type', 0);
// 下面为三个时间字段的列显示
$grid->release_at();
$grid->created_at();
$grid->updated_at();
//filter($callback)方法用来设置表格的简单搜索框
$grid->filter(function ($filter) {
//1.时间段筛选 设置created_at字段的范围查询
$filter->between('created_at', '筛选时间')->datetime();
//2.字段模糊查询 like = '% %'
$filter->like('name', '姓名');
//3.字段equal 筛选
$filter->equal('status', '状态')->select([0 => '下线', 1 => '上线']);
//4.去掉默认的ID搜索
$filter->disableIdFilter();
//5.
});
$grid->disableExport();
$grid->disableCreateButton();
$grid->disableRowSelector();
$form->disableReset();
$grid->actions(function ($actions) {
//关闭删除
$actions->disableDelete();
//关闭编辑
$actions->disableEdit();
//自定义操作按钮
$actions->append('<button type="button" class="btn btn-danger noShow" data-id="' . $actions->getKey() . '" >隐藏</button>');
});
$grid->tools(function ($tools) {
//关闭批量删除
$tools->batch(function ($batch) {
$batch->disableDelete();
});
});
$form->disableReset();
//默认展示$data['name']的值,新接收的值存储user表name字段
$form->text('user.name', '名称')->default($data['name']);
$form->image('user.logo', 'logo')
#随机文件名
->uniqueName()
#验证文件格式('mimes:doc,docx,xlsx');
->rules('mimes:png')
#输入框下边的help提示语
->help($str);
$form->url('user.website', '官网')
#默认填充url 传参
->default($url)
#提示的url
->help('eg: http://www.aware.bi');
#下拉框展示$message提示语
$form->multipleSelect('project.tags1', $message)
#下拉框数据
->options($tags['children']);
$types = array('0'=>'教育','1'=>'医疗');
$form->select('type', '类型')->options($types);
$users = User::all()->pluck('name', 'id')->toArray();
$form->editor('detail', '详细介绍');
$states = [
'on' => ['value' => 1, 'text' => '上线', 'color' => 'success'],
'off' => ['value' => 0, 'text' => '下线', 'color' => 'danger'],
];
$form->switch('status', '上/下线')->states($states);
$form->hidden('is_in');
$form->saving(function (Form $form) {
#指定值为固定1
$form->is_in = 1;
#验证值是够有重复
if($from->nick_name !== $form->model()->email && User::where('email',$form->email)->value('id')){
#错误信息提示
$error = new MessageBag(['title'=>'提示','message'=>'邮箱已存在!']);
return back()->withInput()->with(compact('error'));
}
});
$grid->actions(function ($actions) {
//自定义操作按钮
$actions->append('<button type="button" class="btn btn-danger noShow"
data-id="' . $actions->getKey() . '" >隐藏</button>');
//当前数据的ID
});
$js = <<<EOD
<script>
//隐藏的点击事件
$(document).on('click', '.noShow', function() {
//获取的ID
var id = $(this).data('id');
console.log(id);
swal({
title: "确认隐藏?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "确认",
closeOnConfirm: false,
cancelButtonText: "取消"
},
function(){
$.ajax({
method: 'post',
url: '/admin/articles/hidden',
data: {
//文章ID
id:id,
//post请求token
_token:LA.token,
},
success: function (data) {
$.pjax.reload('#pjax-container');
if (typeof data === 'object') {
if (data.status == 1) {
swal(data.msg, '', 'success');
} else {
swal(data.msg, '', 'error');
}
}
}
})
}
)
});
</script>
EOD;
//传递到页面
$content->body($js);
//执行你的model
$content->body();