model = $publicity; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(PublicityAdminRequest $request) { if ($request->wantsJson()) { $array = $this->model->json(); foreach ($array as $key => $row) { $array[$key] = array_only($row, config('publicity.publicity.listfields')); } return ['data' => $array]; } $this->theme->prependTitle(trans('publicity::publicity.names').' :: '); return $this->theme->of('publicity::admin.publicity.index')->render(); } /** * Display the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function show(PublicityAdminRequest $request, $id) { $publicity = $this->model->find($id); if (empty($publicity)) { if ($request->wantsJson()) { return []; } return view('publicity::admin.publicity.new'); } if ($request->wantsJson()) { return $publicity; } Former::populate($publicity); return view('publicity::admin.publicity.show', compact('publicity')); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(PublicityAdminRequest $request) { $publicity = $this->model->findOrNew(0); Former::populate($publicity); return view('publicity::admin.publicity.create', compact('publicity')); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(PublicityAdminRequest $request) { try { $attributes = $request->all(); $publicity = $this->model->create($attributes); return $this->success(trans('messages.success.created', ['Module' => trans('publicity::publicity.name')])); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function edit(PublicityAdminRequest $request, $id) { $publicity = $this->model->find($id); Former::populate($publicity); return view('publicity::admin.publicity.edit', compact('publicity')); } /** * Update the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function update(PublicityAdminRequest $request, $id) { try { $attributes = $request->all(); $publicity = $this->model->update($attributes, $id); return $this->success(trans('messages.success.updated', ['Module' => trans('publicity::publicity.name')])); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(PublicityAdminRequest $request, $id) { try { $this->model->delete($id); return $this->success(trans('message.success.deleted', ['Module' => trans('publicity::publicity.name')]), 200); } catch (Exception $e) { return $this->error($e->getMessage()); } } }