
最佳答案



讨论数量:
use App\Models\Admin;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class SetManager extends BatchAction
{
public $name = '修改负责人';
protected $selector = '.set-manager';
public function handle(Collection $collection,Request $request)
{ $id = $request->get('manager_id');
DB::transaction(function ()use($collection,$id){
foreach ($collection as $model) {
$model->manager_id = $id;
$model->save();
} });
return $this->response()->success('设置成功')->refresh();
}
public function form()
{ $oAdmins = Admin::query()->where('id','!=',1)->pluck('truename','id');
$this->select('manager_id', '负责人')
->options($oAdmins)->rules('required',['required'=>'请先选择负责人']);
}
public function html()
{ return "<a class='set-manager btn btn-sm btn-success'><i class='fa fa-info-circle'></i>修改负责人</a>";
}}