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