repository = $tutorial; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\B2buy\Tutorial\Repositories\Criteria\TutorialResourceCriteria::class); } /** * Display a list of tutorial. * * @return Response */ public function index(TutorialRequest $request) { return $this->repository ->setPresenter(\B2buy\Tutorial\Repositories\Presenter\TutorialPresenter::class) ->paginate(); } /** * Display tutorial. * * @param Request $request * @param Model $tutorial * * @return Response */ public function show(TutorialRequest $request, Tutorial $tutorial) { return $tutorial->setPresenter(\B2buy\Tutorial\Repositories\Presenter\TutorialListPresenter::class); ; } /** * Create new tutorial. * * @param Request $request * * @return Response */ public function store(TutorialRequest $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('tutorial::tutorial.name')]); $code = 204; $status = 'success'; $url = guard_url('tutorial/tutorial/' . $tutorial->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('tutorial/tutorial'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the tutorial. * * @param Request $request * @param Model $tutorial * * @return Response */ public function update(TutorialRequest $request, Tutorial $tutorial) { try { $data = $request->all(); $tutorial->update($data); $message = trans('messages.success.updated', ['Module' => trans('tutorial::tutorial.name')]); $code = 204; $status = 'success'; $url = guard_url('tutorial/tutorial/' . $tutorial->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('tutorial/tutorial/' . $tutorial->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the tutorial. * * @param Model $tutorial * * @return Response */ public function destroy(TutorialRequest $request, Tutorial $tutorial) { try { $tutorial->delete(); $message = trans('messages.success.deleted', ['Module' => trans('tutorial::tutorial.name')]); $code = 202; $status = 'success'; $url = guard_url('tutorial/tutorial/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('tutorial/tutorial/' . $tutorial->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); } }