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