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) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\B2buy\Tutorial\Repositories\Presenter\TutorialPresenter::class) ->$function(); } $tutorials = $this->repository->paginate(); return $this->response->setMetaTitle(trans('tutorial::tutorial.names')) ->view('tutorial::tutorial.index', true) ->data(compact('tutorials', 'view')) ->output(); } /** * Display tutorial. * * @param Request $request * @param Model $tutorial * * @return Response */ public function show(TutorialRequest $request, Tutorial $tutorial) { if ($tutorial->exists) { $view = 'tutorial::tutorial.show'; } else { $view = 'tutorial::tutorial.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('tutorial::tutorial.name')) ->data(compact('tutorial')) ->view($view, true) ->output(); } /** * Show the form for creating a new tutorial. * * @param Request $request * * @return Response */ public function create(TutorialRequest $request) { $tutorial = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('tutorial::tutorial.name')) ->view('tutorial::tutorial.create', true) ->data(compact('tutorial')) ->output(); } /** * Create new tutorial. * * @param Request $request * * @return Response */ public function store(TutorialRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $tutorial = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('tutorial::tutorial.name')])) ->code(204) ->status('success') ->url(guard_url('tutorial/tutorial/' . $tutorial->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/tutorial/tutorial')) ->redirect(); } } /** * Show tutorial for editing. * * @param Request $request * @param Model $tutorial * * @return Response */ public function edit(TutorialRequest $request, Tutorial $tutorial) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('tutorial::tutorial.name')) ->view('tutorial::tutorial.edit', true) ->data(compact('tutorial')) ->output(); } /** * Update the tutorial. * * @param Request $request * @param Model $tutorial * * @return Response */ public function update(TutorialRequest $request, Tutorial $tutorial) { try { $attributes = $request->all(); $tutorial->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('tutorial::tutorial.name')])) ->code(204) ->status('success') ->url(guard_url('tutorial/tutorial/' . $tutorial->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('tutorial/tutorial/' . $tutorial->getRouteKey())) ->redirect(); } } /** * Remove the tutorial. * * @param Model $tutorial * * @return Response */ public function destroy(TutorialRequest $request, Tutorial $tutorial) { try { $tutorial->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('tutorial::tutorial.name')])) ->code(202) ->status('success') ->url(guard_url('tutorial/tutorial/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('tutorial/tutorial/' . $tutorial->getRouteKey())) ->redirect(); } } /** * Remove multiple tutorial. * * @param Model $tutorial * * @return Response */ public function delete(TutorialRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('tutorial::tutorial.name')])) ->status("success") ->code(202) ->url(guard_url('tutorial/tutorial')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/tutorial/tutorial')) ->redirect(); } } /** * Restore deleted tutorials. * * @param Model $tutorial * * @return Response */ public function restore(TutorialRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('tutorial::tutorial.name')])) ->status("success") ->code(202) ->url(guard_url('/tutorial/tutorial')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/tutorial/tutorial/')) ->redirect(); } } }