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 - Laravel Tutorial
From the course: Building a Website with Laravel, React.js, and Inertia
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
-
-
-
-
React and Laravel setup3m 32s
-
(Locked)
Creating the Home and About pages1m 52s
-
(Locked)
Creating website navigation3m 24s
-
(Locked)
Displaying posts on a website2m 10s
-
(Locked)
Refactoring to components1m 52s
-
(Locked)
Fetching posts from Laravel API2m 22s
-
(Locked)
Creating a new post3m 43s
-
(Locked)
Updating a post2m 40s
-
(Locked)
Deleting a post1m 42s
-
(Locked)
Challenge: Show individual post page56s
-
(Locked)
Solution: Show individual post page2m 4s
-
-
-