repository = $tutorial; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Dipendra\Programming\Repositories\Criteria\TutorialUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(TutorialRequest $request) { $tutorials = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('programming::tutorial.names')); return $this->theme->of('programming::user.tutorial.index', compact('tutorials'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Tutorial $tutorial * * @return Response */ public function show(TutorialRequest $request, Tutorial $tutorial) { Form::populate($tutorial); return $this->theme->of('programming::user.tutorial.show', compact('tutorial'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(TutorialRequest $request) { $tutorial = $this->repository->newInstance([]); Form::populate($tutorial); $this->theme->prependTitle(trans('programming::tutorial.names')); return $this->theme->of('programming::user.tutorial.create', compact('tutorial'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(TutorialRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $tutorial = $this->repository->create($attributes); return redirect(trans_url('/user/programming/tutorial')) -> with('message', trans('messages.success.created', ['Module' => trans('programming::tutorial.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Tutorial $tutorial * * @return Response */ public function edit(TutorialRequest $request, Tutorial $tutorial) { Form::populate($tutorial); $this->theme->prependTitle(trans('programming::tutorial.names')); return $this->theme->of('programming::user.tutorial.edit', compact('tutorial'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Tutorial $tutorial * * @return Response */ public function update(TutorialRequest $request, Tutorial $tutorial) { try { $this->repository->update($request->all(), $tutorial->getRouteKey()); return redirect(trans_url('/user/programming/tutorial')) ->with('message', trans('messages.success.updated', ['Module' => trans('programming::tutorial.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(TutorialRequest $request, Tutorial $tutorial) { try { $this->repository->delete($tutorial->getRouteKey()); return redirect(trans_url('/user/programming/tutorial')) ->with('message', trans('messages.success.deleted', ['Module' => trans('programming::tutorial.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }