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