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