<?php

namespace App\Admin\Actions\Post;

use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

class BatchStatus extends BatchAction
{
    public $name = '批量修改状态';

    public function handle(Collection $collection)
    {
        foreach ($collection as $model) {
            // 双向修改 未读、已读
            // $model->status = (int)!$model->status;
            // 单向操作 只改为已读
            $model->status = 1;
            $model->save();
        }

        return $this->response()->success('Success!')->refresh();
    }

}

class BatchMsg extends BatchAction
{
    public $name = '批量回复';

    public function handle(Collection $collection, Request $request){
        foreach ($collection as $model) {
            $msg = $request->get('msg');
            $model->save('msg', $msg);
        }

        return $this->response()->success('Success!')->refresh();
    }

    public function form(){
        $this->textarea('msg', '回复内容');
        $this->textarea('msg', '回复内容');
    }
}