controller.stub 1.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php
/**
 * Created by PhpStorm.
 * User: %user%
 * Date: %date%
 * Time: %time%
 * Description:
 */

namespace App\Controller;

use App\Repository\Interfaces\%ModelClass%Repository;
use Hyperf\Di\Annotation\Inject;
use Meibuyu\Micro\Annotation\AutoPerm;
use Meibuyu\Micro\Annotation\Perm;

/**
 * @AutoPerm()
 * Class %ModelClass%Controller
 * @package App\Controller
 */
class %ModelClass%Controller extends AbstractController
{
王源's avatar
王源 committed
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    /**
     * @Inject()
     * @var %ModelClass%Repository
     */
    private $repository;

    /**
     * 获取列表数据
     * @return mixed
     */
    public function index()
    {
        $list = $this->repository->list();
        return success('获取成功', $list);
    }

    /**
     * 获取列表数据
     * @Perm("index")
王源's avatar
王源 committed
44
     * @param int $id id编号
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
     * @return mixed
     */
    public function show($id)
    {
        $data = $this->repository->show($id);
        return success('获取成功', $data);
    }

    /**
     * 添加记录
     * @return mixed
     */
    public function create()
    {
        $data = $this->repository->create($this->request->all());
        return success('创建成功', $data);
    }

    /**
     * 更新数据
王源's avatar
王源 committed
65
     * @param int $id id编号
66 67 68 69 70 71 72 73 74 75
     * @return mixed
     */
    public function update($id)
    {
        $data = $this->repository->update($this->request->all(), $id);
        return success('更新成功', $data);
    }

    /**
     * 删除单条数据
王源's avatar
王源 committed
76
     * @param int $id id编号
77 78 79 80 81 82 83 84 85
     * @return mixed
     */
    public function delete($id)
    {
        $deleted = $this->repository->delete($id);
        return success('删除成功', $deleted);
    }
    %rs%
}