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