repository = $sahbaj; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(SahbajUserWebRequest $request) { $this->repository->pushCriteria(new \Lavalite\Sahbaj\Repositories\Criteria\SahbajUserCriteria()); $sahbajs = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('sahbaj::sahbaj.names').' :: '); return $this->theme->of('sahbaj::user.sahbaj.index', compact('sahbajs'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Sahbaj $sahbaj * * @return Response */ public function show(SahbajUserWebRequest $request, Sahbaj $sahbaj) { Form::populate($sahbaj); return $this->theme->of('sahbaj::user.sahbaj.show', compact('sahbaj'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(SahbajUserWebRequest $request) { $sahbaj = $this->repository->newInstance([]); Form::populate($sahbaj); return $this->theme->of('sahbaj::user.sahbaj.create', compact('sahbaj'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(SahbajUserWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $sahbaj = $this->repository->create($attributes); return redirect(trans_url('/user/sahbaj/sahbaj')) -> with('message', trans('messages.success.created', ['Module' => trans('sahbaj::sahbaj.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 Sahbaj $sahbaj * * @return Response */ public function edit(SahbajUserWebRequest $request, Sahbaj $sahbaj) { Form::populate($sahbaj); return $this->theme->of('sahbaj::user.sahbaj.edit', compact('sahbaj'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Sahbaj $sahbaj * * @return Response */ public function update(SahbajUserWebRequest $request, Sahbaj $sahbaj) { try { $this->repository->update($request->all(), $sahbaj->getRouteKey()); return redirect(trans_url('/user/sahbaj/sahbaj')) ->with('message', trans('messages.success.updated', ['Module' => trans('sahbaj::sahbaj.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(SahbajUserWebRequest $request, Sahbaj $sahbaj) { try { $this->repository->delete($sahbaj->getRouteKey()); return redirect(trans_url('/user/sahbaj/sahbaj')) ->with('message', trans('messages.success.deleted', ['Module' => trans('sahbaj::sahbaj.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }