From the course: Building a Website with Laravel, React.js, and Inertia

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Creating a new post

Creating a new post

- [Instructor] Now that we are displaying existing posts, let's create a new post and send it to the create endpoint that will save the post in the database. We will add buttons somewhere up here to take us to the form, but first we need to create a new route and add it to the routes in the app.jsx file. The route will be posts/create and it will return the post create component, which we will create in just a second. Let's also import the create component here at the top. And now in our pages/posts directory, we'll create the JSX file. I'm going to paste the code here and then we will go over it together. We are using the useState hook to manage the input values for the title, author, and body with the default state being an empty string. We will code the handleSubmit function on form submit that will take the values of each input field and send the post request with Axios. Then we clear the input fields by resetting their corresponding state variables to an empty string, and the…

Contents