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