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