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