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