/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Requests\PostsFormRequest $request) { $post = Posts::findOrFail($id); $input = $request->all(); $input['alias'] = HelperFunctions::str2url($request->title); $post->update($input); $categories_ids = []; foreach ($input['categories_list'] as $value) { $category = Categories::findOrNew($value); if ($category->exists) { array_push($categories_ids, $value); } else { $category->name = $value; $category->save(); array_push($categories_ids, $category->id); } } $post->categories()->sync($categories_ids); $tags_ids = []; foreach ($input['tags_list'] as $value) { $tag = Tags::findOrNew($value); if ($tag->exists) { array_push($tags_ids, $value); } else { $tag->name = $value; $tag->save(); array_push($tags_ids, $tag->id); } } $post->tags()->sync($tags_ids); \Session::flash('success', 'Post updated'); return redirect('/'); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(PostsFormRequest $request) { // $user = Sentinel::getUser()->id; $post = new Post(); //$post -> user_id = Auth::id(); $post->user_id = $user; $post->headline = $request->headline; $post->media_mention = \Input::get('media_mention') == 1 ? 1 : 0; $post->presentation = \Input::get('presentation') == 1 ? 1 : 0; $post->meeting = \Input::get('meeting') == 1 ? 1 : 0; $post->sponsored_event = \Input::get('sponsored_event') == 1 ? 1 : 0; $post->on_campus_collaboration = \Input::get('on_campus_collaboration') == 1 ? 1 : 0; $post->off_campus_collaboration = \Input::get('off_campus_collaboration') == 1 ? 1 : 0; $post->development = \Input::get('development') == 1 ? 1 : 0; $post->satifaction_survey = \Input::get('satifaction_survey') == 1 ? 1 : 0; $post->achievement = \Input::get('achievement') == 1 ? 1 : 0; $post->testimonial = \Input::get('testimonial') == 1 ? 1 : 0; $post->other = \Input::get('other') == 1 ? 1 : 0; $post->other_desc = $request->other_desc; //$post -> source_id = ($request->source_id == null) ? null : $request->source_id; $post->publish_date = $request->publish_date == null ? null : date('Y-m-d', strtotime($request->publish_date)); $post->writer_collaborator = $request->writer_collaborator; //$post -> department_id = ($request->department_id == null) ? null : $request->department_id; //$post -> project_id = ($request->project_id == null) ? null : $request->project_id; $post->notes = $request->notes; $post->url = $request->url; if ($request->file('attachment')) { $file = $request->file('attachment'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $name = $user . '-' . time() . '-' . str_slug($filename, "-") . '.' . $extension; //$file = $file->move('/var/www/vhosts/lgscharlotte.org/private/uploads/', $name); $file = $file->move(public_path() . '/resources/', $name); $post->attachment = $name; } // $attachment = ""; // if(Input::hasFile('attachment')) // { // $file = Input::file('attachment'); // $filename = $file->getClientOriginalName(); // $extension = $file -> getClientOriginalExtension(); // $picture = sha1($filename . time()) . '.' . $extension; // } // $post -> attachment = $attachment; $post->save(); if (Input::get('staff_list')) { $post->staffs()->attach(Input::get('staff_list')); } if (Input::get('department_list')) { $post->departments()->attach(Input::get('department_list')); } if (Input::get('source_list')) { $this->syncSources($post, $request); } // // Move the files // if(Input::hasFile('attachment')) // { // $destinationPath = public_path() . '/resources/'.$post->id.'/'; // Input::file('attachment')->move($destinationPath, $attachment); // } if ($request->submitVal) { return \Redirect::route('manage.posts.create', array($post->id))->with('success', 'Your post has been created!'); } else { return \Redirect::route('manage.posts.index', array($post->id))->with('success', 'Your post has been created!'); } }