Skip to content

批量操作

table设置批量操作

php
 $table->tools(function (Grid\Tools $tools) {
            $tools->batch(function (Grid\Tools\BatchActions $batchActions){
                $batchActions->add("启用", new SwitchFun(["action"=>1]));
                $batchActions->add("禁用", new SwitchFun(["action"=>0]));
            });
        });

批量处理类

php
<?php

namespace LinAdmin\example\Action;

use Encore\Admin\Grid\Tools\NewBatchAction;
use Encore\Admin\Url;
use LinAdmin\example\Model\Testdata;

class SwitchFun extends NewBatchAction
{
    public function handle($id_list)
    {
        $model = Testdata::class;
        $action = $this->payload["action"];
        $model::whereIn("id", $id_list)->update([
            "level" => $action,
        ]);
        $url = Url::generate("testbase","index",["_p"=>"test"]);
        $this->successRedirect($url);
    }

}