middleware('web'); $this->middleware('auth:web'); $this->setupTheme(config('theme.themes.user.theme'), config('theme.themes.user.layout')); $this->repository = $report; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(ReportUserWebRequest $request) { $this->repository->pushCriteria(new \Assetproject\Report\Repositories\Criteria\ReportUserCriteria()); $reports = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('report::report.names').' :: '); return $this->theme->of('report::user.report.index', compact('reports'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Report $report * * @return Response */ public function show(ReportUserWebRequest $request, Report $report) { Form::populate($report); return $this->theme->of('report::user.report.show', compact('report'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(ReportUserWebRequest $request) { $report = $this->repository->newInstance([]); Form::populate($report); return $this->theme->of('report::user.report.create', compact('report'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(ReportUserWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $report = $this->repository->create($attributes); return redirect(trans_url('/user/report/report')) -> with('message', trans('messages.success.created', ['Module' => trans('report::report.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 Report $report * * @return Response */ public function edit(ReportUserWebRequest $request, Report $report) { Form::populate($report); return $this->theme->of('report::user.report.edit', compact('report'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Report $report * * @return Response */ public function update(ReportUserWebRequest $request, Report $report) { try { $this->repository->update($request->all(), $report->getRouteKey()); return redirect(trans_url('/user/report/report')) ->with('message', trans('messages.success.updated', ['Module' => trans('report::report.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(ReportUserWebRequest $request, Report $report) { try { $this->repository->delete($report->getRouteKey()); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('report::report.name')]), 'code' => 202, 'redirect' => trans_url('/user/report/report/0'), ], 202); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }