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