123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Http\Controllers\Api\Course;
- use App\Http\Controllers\Controller;
- use Illuminate\Http\Request;
- use Jiannei\Response\Laravel\Support\Facades\Response;
- use Prettus\Validator\Contracts\ValidatorInterface;
- use App\Contracts\Repositories\Course\CommentRepository;
- use App\Repositories\Validators\Course\CommentValidator;
- /**
- * Class CourseCommentsController.
- *
- * @package namespace App\Http\Controllers;
- */
- class CommentController extends Controller
- {
- /**
- * @var CommentRepository
- */
- protected $repository;
- /**
- * @var CommentValidator
- */
- protected $validator;
- /**
- * CourseCommentsController constructor.
- *
- * @param CommentRepository $repository
- * @param CommentValidator $validator
- */
- public function __construct(CommentRepository $repository, CommentValidator $validator)
- {
- $this->repository = $repository;
- $this->validator = $validator;
- }
- public function store(Request $request)
- {
- $this->validate($request, $this->validator->getRules(ValidatorInterface::RULE_CREATE));
- try {
- $data = $request->only(array_keys($this->validator->getRules(ValidatorInterface::RULE_CREATE)));
- $data['user_id'] = login_user_id();
- $comment = $this->repository->create($data);
- return Response::success($comment);
- } catch (\Exception $e) {
- return $this->errorStore($e);
- }
- }
- public function videoComments($video_id)
- {
- $comments = $this->repository->where('course_video_id', $video_id)->paginate(request('per_page', self::PAGE_NUM));
- return Response::success($this->repository->parserResult($comments));
- }
- public function courseComments($course_id)
- {
- $comments = $this->repository->where('course_id', $course_id)->paginate(request('per_page', self::PAGE_NUM));
- return Response::success($this->repository->parserResult($comments));
- }
- }
|