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