In order to actually create a post, we'll need to create a route and handle the form input.
1. Open
index.php
.2. Create a basic
post
route, and call itpost
.post('/post', function($app) { });
3. Inside our
post
route, let's accept the value of the passed valuecontent
and use thecreate
function on ourPost
class to actually create the post. Once the post is created, we'll redirect the user back to their profile.post('/post', function($app) { $post = new Post(); $post->content = $app->form('content'); $post->create(); $app->redirect('/user/' . User::current_user()); });
4. We've done quite a bit to make sure that the user is authenticated when creating a post, but let's triple check that the user is authenticated here. If it turns out that they aren't authenticated, our application will forward them to the user login page with an error message.
post('/post', function($app) { if (User::is_authenticated...