/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //Use Input::get(<inputname>) to get value $rules = array('title' => 'required', 'summary' => 'required|max:200', 'content' => 'required', 'slug' => 'required|max:100', 'blogid' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { echo "SDSDFSDF"; var_dump($validator->messages()); var_dump($validator); /*return Redirect::to(route('blogs.posts.create')) ->withErrors($validator) ->withInput(); */ } else { $newpostdata = array('title' => Input::get('title'), 'summary' => Input::get('summary'), 'content' => Input::get('content'), 'slug' => Input::get('slug'), 'blog_id' => Input::get('blogid'), 'author_id' => Auth::user()['id']); $newpostentry = Posts::create($newpostdata); $saved = $newpostentry->save(); if (!$saved) { NamBlog::abort(500, 'Error'); } else { $currblog = Blogs::where('id', $newpostdata['blog_id'])->first(); return Redirect::to(route('blogs.show', $currblog['slug'])); } } }
public function update($blog, $comment) { $rules = array('name' => 'required', 'email' => 'required|email', 'message' => 'required', 'comment_id' => 'required|int'); $validator = Validator::make(Input::all(), $rules); $validator->after(function ($validator) { if ($this->checkpostandusertally(Input::get('comment_id'))) { $validator->errors()->add('field', 'Something is wrong with this field!'); } }); if ($validator->fails()) { return Redirect::to(route('comment.edit', [$blog->slug, $post->slug, $comment->id]))->withErrors($validator)->withInput(); } else { $updatedcommentdata = array('name' => Input::get('name'), 'email' => Input::get('email'), 'message' => Input::get('message')); $updatedcomment = Comment::where('id', Input::get('comment_id'))->update($updatedcommentdata); if (!$updatedcomment) { return NamBlog::abort(500, 'Error'); } else { Flash::message("Comment (id: " . Input::get('comment_id') . ") has been updated!"); return Redirect::to(route('comment.edit', [$blog->slug, $comment->id])); } } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Blogs $blog) { $rules = array('title' => 'required', 'description' => 'required|max:200', 'slug' => 'required|max:100', 'type' => 'required|in:public,private'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/blogs/create')->withErrors($validator)->withInput(); } else { $updatedblogdata = array('title' => Input::get('title'), 'description' => Input::get('description'), 'slug' => Input::get('slug'), 'type' => Input::get('type'), 'owner' => Auth::user()['id']); $updatedblog = Blogs::where('id', $blog['id'])->update($updatedblogdata); if (!$updatedblog) { NamBlog::abort(500, 'Error'); } else { return Redirect::to(route('blogs.manage', [$blog->slug])); } } }