catchAdmin/catch/system/controller/Attachments.php

32 lines
789 B
PHP
Raw Normal View History

2020-04-29 17:37:45 +08:00
<?php
namespace catchAdmin\system\controller;
use catcher\base\CatchController;
use catcher\CatchResponse;
use catchAdmin\system\model\Attachments as AttachmentsModel;
use catcher\Utils;
use think\facade\Filesystem;
class Attachments extends CatchController
{
public function index(AttachmentsModel $model)
{
return CatchResponse::paginate($model->getList());
}
public function delete($id, AttachmentsModel $model)
{
$ids = Utils::stringToArrayBy($id);
foreach ($ids as $id) {
$attachment = $model->findBy($id);
if ($attachment && $model->deleteBy($id)) {
Filesystem::delete($attachment->path);
}
}
return CatchResponse::success();
}
}