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