repository = $mahasiswa; parent::__construct(); } /** * Display a list of mahasiswa. * * @return Response */ public function index(MahasiswaRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('mahasiswa::mahasiswa.names').' :: '); return $this->theme->of('mahasiswa::admin.mahasiswa.index')->render(); } /** * Display a list of mahasiswa. * * @return Response */ public function getJson(MahasiswaRequest $request) { $pageLimit = $request->input('pageLimit'); $mahasiswas = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Mahasiswa\\Mahasiswa\\Repositories\\Presenter\\MahasiswaListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $mahasiswas['recordsTotal'] = $mahasiswas['meta']['pagination']['total']; $mahasiswas['recordsFiltered'] = $mahasiswas['meta']['pagination']['total']; $mahasiswas['request'] = $request->all(); return response()->json($mahasiswas, 200); } /** * Display mahasiswa. * * @param Request $request * @param Model $mahasiswa * * @return Response */ public function show(MahasiswaRequest $request, Mahasiswa $mahasiswa) { if (!$mahasiswa->exists) { return response()->view('mahasiswa::admin.mahasiswa.new', compact('mahasiswa')); } Form::populate($mahasiswa); return response()->view('mahasiswa::admin.mahasiswa.show', compact('mahasiswa')); } /** * Show the form for creating a new mahasiswa. * * @param Request $request * * @return Response */ public function create(MahasiswaRequest $request) { $mahasiswa = $this->repository->newInstance([]); Form::populate($mahasiswa); return response()->view('mahasiswa::admin.mahasiswa.create', compact('mahasiswa')); } /** * Create new mahasiswa. * * @param Request $request * * @return Response */ public function store(MahasiswaRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $mahasiswa = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('mahasiswa::mahasiswa.name')]), 'code' => 204, 'redirect' => trans_url('/admin/mahasiswa/mahasiswa/'.$mahasiswa->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show mahasiswa for editing. * * @param Request $request * @param Model $mahasiswa * * @return Response */ public function edit(MahasiswaRequest $request, Mahasiswa $mahasiswa) { Form::populate($mahasiswa); return response()->view('mahasiswa::admin.mahasiswa.edit', compact('mahasiswa')); } /** * Update the mahasiswa. * * @param Request $request * @param Model $mahasiswa * * @return Response */ public function update(MahasiswaRequest $request, Mahasiswa $mahasiswa) { try { $attributes = $request->all(); $mahasiswa->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('mahasiswa::mahasiswa.name')]), 'code' => 204, 'redirect' => trans_url('/admin/mahasiswa/mahasiswa/'.$mahasiswa->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/mahasiswa/mahasiswa/'.$mahasiswa->getRouteKey()), ], 400); } } /** * Remove the mahasiswa. * * @param Model $mahasiswa * * @return Response */ public function destroy(MahasiswaRequest $request, Mahasiswa $mahasiswa) { try { $t = $mahasiswa->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('mahasiswa::mahasiswa.name')]), 'code' => 202, 'redirect' => trans_url('/admin/mahasiswa/mahasiswa/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/mahasiswa/mahasiswa/'.$mahasiswa->getRouteKey()), ], 400); } } }