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