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