123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Http\Controllers\Api\Course;
- use App\Http\Controllers\Controller;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Enums\ResponseCodeEnum;
- use Illuminate\Http\Request;
- use Jiannei\Response\Laravel\Support\Facades\Response;
- use Prettus\Validator\Contracts\ValidatorInterface;
- use App\Contracts\Repositories\Course\CategoryRepository;
- use App\Repositories\Validators\Course\CategoryValidator;
- /**
- * Class CourseCategoriesController.
- *
- * @package namespace App\Http\Controllers;
- */
- class CategoryController extends Controller
- {
- /**
- * @var CategoryRepository
- */
- protected $repository;
- /**
- * @var CategoryValidator
- */
- protected $validator;
- /**
- * CourseCategoriesController constructor.
- *
- * @param CategoryRepository $repository
- * @param CategoryValidator $validator
- */
- public function __construct(CategoryRepository $repository, CategoryValidator $validator)
- {
- $this->repository = $repository;
- $this->validator = $validator;
- }
- public function tree()
- {
- $departments = $this->repository->orderByDesc('sort')->get()->append('parent_name')->toArray();
- return Response::success(toTree($departments));
- }
- public function index(Request $request)
- {
- if ($id = $request->get('id', false)) {
- $category = $this->repository->skipPresenter()->where('status', ModelStatusEnum::OK)->where('parent_id', $id)->get(['id', 'name']);
- } else {
- $category = $this->repository->skipPresenter()->where('status', ModelStatusEnum::OK)->where('parent_id', 0)->get(['id', 'name']);
- }
- return Response::success($category);
- }
- }
|