<?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 = '批量修改状态';
    protected $selector = '.report-posts';

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

        return $this->response()->success('修改成功!')->refresh();
    }
    
    // public function html()
    // {        
    //     return "<a class='status-posts btn btn-sm btn-success'><i>aaaaaaaaaaa</i>批量修改状态</a>";
    // }
}