repository = $topic; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Course\Repositories\Criteria\TopicResourceCriteria::class); } /** * Display a list of topic. * * @return Response */ public function index(TopicRequest $request) { return $this->repository ->setPresenter(\Litepie\Course\Repositories\Presenter\TopicPresenter::class) ->paginate(); } /** * Display topic. * * @param Request $request * @param Model $topic * * @return Response */ public function show(TopicRequest $request, Topic $topic) { return $topic->setPresenter(\Litepie\Course\Repositories\Presenter\TopicListPresenter::class); ; } /** * Create new topic. * * @param Request $request * * @return Response */ public function store(TopicRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('course::topic.name')]); $code = 204; $status = 'success'; $url = guard_url('course/topic/' . $topic->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/topic'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the topic. * * @param Request $request * @param Model $topic * * @return Response */ public function update(TopicRequest $request, Topic $topic) { try { $data = $request->all(); $topic->update($data); $message = trans('messages.success.updated', ['Module' => trans('course::topic.name')]); $code = 204; $status = 'success'; $url = guard_url('course/topic/' . $topic->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/topic/' . $topic->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the topic. * * @param Model $topic * * @return Response */ public function destroy(TopicRequest $request, Topic $topic) { try { $topic->delete(); $message = trans('messages.success.deleted', ['Module' => trans('course::topic.name')]); $code = 202; $status = 'success'; $url = guard_url('course/topic/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/topic/' . $topic->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }