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