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