public function create() { if ($this->auth->guest()) { $this->app->flash("info", "You must be logged in to create a post"); $this->app->redirect("/login"); } else { $request = $this->app->request; $title = $request->post('title'); $content = $request->post('content'); $token = $request->post('csrf_token'); $payed = $request->post('ispayedpost'); $author = $this->auth->user()->getUsername(); // Username of logged in user $date = date("dmY"); $missingBankAccountWhenNeeded = $payed == '1' && $this->auth->user()->getBankcard() == ''; $validation = new PostValidation($title, $author, $content, $token, $missingBankAccountWhenNeeded); if ($validation->isGoodToGo()) { $post = new Post(); $post->setAuthor($author); $post->setTitle($title); $post->setContent($content); $post->setDate($date); $post->setIsPayedPost($payed); $savedPost = $this->postRepository->save($post); $this->app->redirect('/posts/' . $savedPost . '?msg=Post succesfully posted'); } } $this->app->flash('error', join('<br>', $validation->getValidationErrors())); $this->app->redirect('/posts/new'); // RENDER HERE }