repository = $kitchen; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Restaurant\Kitchen\Repositories\Criteria\KitchenResourceCriteria::class); } /** * Display a list of kitchen. * * @return Response */ public function index(KitchenRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Restaurant\Kitchen\Repositories\Presenter\KitchenPresenter::class) ->$function(); } $kitchens = $this->repository->paginate(); return $this->response->title(trans('kitchen::kitchen.names')) ->view('kitchen::kitchen.index', true) ->data(compact('kitchens')) ->output(); } /** * Display kitchen. * * @param Request $request * @param Model $kitchen * * @return Response */ public function show(KitchenRequest $request, Kitchen $kitchen) { if ($kitchen->exists) { $view = 'kitchen::kitchen.show'; } else { $view = 'kitchen::kitchen.new'; } return $this->response->title(trans('app.view') . ' ' . trans('kitchen::kitchen.name')) ->data(compact('kitchen')) ->view($view, true) ->output(); } /** * Show the form for creating a new kitchen. * * @param Request $request * * @return Response */ public function create(KitchenRequest $request) { $kitchen = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('kitchen::kitchen.name')) ->view('kitchen::kitchen.create', true) ->data(compact('kitchen')) ->output(); } /** * Create new kitchen. * * @param Request $request * * @return Response */ public function store(KitchenRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $kitchen = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('kitchen::kitchen.name')])) ->code(204) ->status('success') ->url(guard_url('kitchen/kitchen/' . $kitchen->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/kitchen/kitchen')) ->redirect(); } } /** * Show kitchen for editing. * * @param Request $request * @param Model $kitchen * * @return Response */ public function edit(KitchenRequest $request, Kitchen $kitchen) { return $this->response->title(trans('app.edit') . ' ' . trans('kitchen::kitchen.name')) ->view('kitchen::kitchen.edit', true) ->data(compact('kitchen')) ->output(); } /** * Update the kitchen. * * @param Request $request * @param Model $kitchen * * @return Response */ public function update(KitchenRequest $request, Kitchen $kitchen) { try { $attributes = $request->all(); $kitchen->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('kitchen::kitchen.name')])) ->code(204) ->status('success') ->url(guard_url('kitchen/kitchen/' . $kitchen->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('kitchen/kitchen/' . $kitchen->getRouteKey())) ->redirect(); } } /** * Remove the kitchen. * * @param Model $kitchen * * @return Response */ public function destroy(KitchenRequest $request, Kitchen $kitchen) { try { $kitchen->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('kitchen::kitchen.name')])) ->code(202) ->status('success') ->url(guard_url('kitchen/kitchen/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('kitchen/kitchen/' . $kitchen->getRouteKey())) ->redirect(); } } /** * Remove multiple kitchen. * * @param Model $kitchen * * @return Response */ public function delete(KitchenRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('kitchen::kitchen.name')])) ->status("success") ->code(202) ->url(guard_url('kitchen/kitchen')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/kitchen/kitchen')) ->redirect(); } } /** * Restore deleted kitchens. * * @param Model $kitchen * * @return Response */ public function restore(KitchenRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('kitchen::kitchen.name')])) ->status("success") ->code(202) ->url(guard_url('/kitchen/kitchen')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/kitchen/kitchen/')) ->redirect(); } } }