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