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