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