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