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