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