repository = $entrance; parent::__construct(); } /** * Display a list of entrance. * * @return Response */ public function index(EntranceAdminWebRequest $request) { if ($request->wantsJson()) { $entrances = $this->repository->setPresenter('\\Farabi\\Portal\\Repositories\\Presenter\\EntranceListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($entrances, 200); } $this ->theme->prependTitle(trans('portal::entrance.names').' :: '); return $this->theme->of('portal::admin.entrance.index')->render(); } /** * Display entrance. * * @param Request $request * @param Model $entrance * * @return Response */ public function show(EntranceAdminWebRequest $request, Entrance $entrance) { if (!$entrance->exists) { return response()->view('portal::admin.entrance.new', compact('entrance')); } Form::populate($entrance); return response()->view('portal::admin.entrance.show', compact('entrance')); } /** * Show the form for creating a new entrance. * * @param Request $request * * @return Response */ public function create(EntranceAdminWebRequest $request) { $entrance = $this->repository->newInstance([]); Form::populate($entrance); return response()->view('portal::admin.entrance.create', compact('entrance')); } /** * Create new entrance. * * @param Request $request * * @return Response */ public function store(EntranceAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $entrance = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('portal::entrance.name')]), 'code' => 204, 'redirect' => trans_url('/admin/portal/entrance/'.$entrance->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show entrance for editing. * * @param Request $request * @param Model $entrance * * @return Response */ public function edit(EntranceAdminWebRequest $request, Entrance $entrance) { Form::populate($entrance); return response()->view('portal::admin.entrance.edit', compact('entrance')); } /** * Update the entrance. * * @param Request $request * @param Model $entrance * * @return Response */ public function update(EntranceAdminWebRequest $request, Entrance $entrance) { try { $attributes = $request->all(); $entrance->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('portal::entrance.name')]), 'code' => 204, 'redirect' => trans_url('/admin/portal/entrance/'.$entrance->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/portal/entrance/'.$entrance->getRouteKey()), ], 400); } } /** * Remove the entrance. * * @param Model $entrance * * @return Response */ public function destroy(EntranceAdminWebRequest $request, Entrance $entrance) { try { $t = $entrance->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('portal::entrance.name')]), 'code' => 202, 'redirect' => trans_url('/admin/portal/entrance/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/portal/entrance/'.$entrance->getRouteKey()), ], 400); } } }