public function validatePost($id) { if (!Auth::check()) { return Redirect::to('/login'); } $error = NULL; $title = Input::get('title'); $url = Input::get('url'); $image = NULL; $description = Input::get('description'); $newPostID = NULL; if (!empty($url) && preg_match("#https?://#", $url) == 0) { $url = 'http://' . $url; } if (empty($title)) { $error = 'Enter a title for your post'; } else { if (empty($description)) { $error = 'Enter a description for your post'; } else { $newPost = ['title' => $title, 'description' => $description, 'url' => $url, 'community_id' => $id, 'user_id' => Auth::user()->id, 'comments_count' => 0, 'points' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()]; $newPostID = DB::table('posts')->insertGetId($newPost); } } if ($error) { $community = Community::find($id); return view('newpost', ['community' => $community, 'error' => $error]); } else { return Redirect::to('/post/' . $newPostID); } }
/** * Display a listing of the resource. * * @return Response */ public function index($id) { if (!Auth::check()) { return Redirect::to('/login'); } $community = Community::find($id); return view('community', ['community' => $community, 'posts' => $community->posts]); }