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