form = StoryForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('beo.story.modules'), 'story', guard_url('story')); } /** * Display a list of story. * * @return Response */ public function index(StoryRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Story::pushScope(new RequestScope()) ->pushScope(new StoryResourceScope()) ->simplePaginate($pageLimit); $data = new StoriesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('story::story.names')) ->view('story::story.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display story. * * @param Request $request * @param Model $story * * @return Response */ public function show(StoryRequest $request, Story $model) { $form = $this->form; $modules = $this->modules; $data = new StoryResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('story::story.name')) ->data(compact('data', 'form', 'modules')) ->view('story::story.show') ->output(); } /** * Show the form for creating a new story. * * @param Request $request * * @return Response */ public function create(StoryRequest $request, Story $model) { $form = $this->form; $modules = $this->modules; $data = new StoryResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('story::story.name')) ->view('story::story.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new story. * * @param Request $request * * @return Response */ public function store(StoryRequest $request, Story $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new StoryResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('story::story.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('story/story/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/story/story')) ->redirect(); } } /** * Show story for editing. * * @param Request $request * @param Model $story * * @return Response */ public function edit(StoryRequest $request, Story $model) { $form = $this->form; $modules = $this->modules; $data = new StoryResource($model); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('story::story.name')) ->view('story::story.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the story. * * @param Request $request * @param Model $story * * @return Response */ public function update(StoryRequest $request, Story $model) { try { $attributes = $request->all(); $model = $model->update($attributes); $data = new StoryResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('story::story.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('story/story/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('story/story/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the story. * * @param Model $story * * @return Response */ public function destroy(StoryRequest $request, Story $model) { try { $model->delete(); $data = new StoryResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('story::story.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('story/story/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('story/story/' . $model->getRouteKey())) ->redirect(); } } }