middleware(function ($request, $next) { $this->form = SparePartForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.shop.modules'), 'shop', guard_url('shop')); return $next($request); }); } /** * Display a list of spare_part. * * @return Response */ public function index(SparePartResourceRequest $request) { $request = $request->all(); $page = SparePartActions::run('paginate', $request); $data = new SparePartsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('shop::spare_part.names')) ->view('shop::spare_part.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display spare_part. * * @param Request $request * @param Model $spare_part * * @return Response */ public function show(SparePartResourceRequest $request, SparePart $model) { $form = $this->form; $modules = $this->modules; $data = new SparePartResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('shop::spare_part.name')) ->data(compact('data', 'form', 'modules')) ->view('shop::spare_part.show') ->output(); } /** * Show the form for creating a new spare_part. * * @param Request $request * * @return Response */ public function create(SparePartResourceRequest $request, SparePart $model) { $form = $this->form; $modules = $this->modules; $data = new SparePartResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('shop::spare_part.name')) ->view('shop::spare_part.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new spare_part. * * @param Request $request * * @return Response */ public function store(SparePartResourceRequest $request, SparePart $model) { try { $request = $request->all(); $model = SparePartAction::run('store', $model, $request); $data = new SparePartResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('shop::spare_part.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('shop/spare_part/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/shop/spare_part')) ->redirect(); } } /** * Show spare_part for editing. * * @param Request $request * @param Model $spare_part * * @return Response */ public function edit(SparePartResourceRequest $request, SparePart $model) { $form = $this->form; $modules = $this->modules; $data = new SparePartResource($model); // return view('shop::spare_part.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('shop::spare_part.name')) ->view('shop::spare_part.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the spare_part. * * @param Request $request * @param Model $spare_part * * @return Response */ public function update(SparePartResourceRequest $request, SparePart $model) { try { $request = $request->all(); $model = SparePartAction::run('update', $model, $request); $data = new SparePartResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('shop::spare_part.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('shop/spare_part/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('shop/spare_part/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the spare_part. * * @param Model $spare_part * * @return Response */ public function destroy(SparePartResourceRequest $request, SparePart $model) { try { $request = $request->all(); $model = SparePartAction::run('destroy', $model, $request); $data = new SparePartResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('shop::spare_part.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('shop/spare_part/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('shop/spare_part/' . $model->getRouteKey())) ->redirect(); } } }