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.
Displaying a single post - Laravel Tutorial
From the course: Building a Website with Laravel, React.js, and Inertia
Displaying a single post
- [Instructor] Let's build a way to display a single post now. In the PostController, the show methods, we will retrieve the specific post instance and render the Post/Show component with the post data. Now we need to create a Post/Show component. I'm going to copy what we had in the Show component of our React project and we will fix it up again. We are going to remove the useLocation hook and import Link from inertiajs/react rather than react-router-dom. We also need to accept the post data into the component. To print the current post title, we will just do post.title here instead of location.state.title. And the same goes for the author, post.author. And for the body, post.body. Then, we will change this link to its href instead of to and send it to the home route. Finally, let's import a guest layout and wrap it around our content to style the page nicely. That should be it. Let's test it in the browser. I'm going to click on this heading, and here is our individual post page.
Contents
-
-
-
-
-
(Locked)
Introduction to Inertia.js1m 16s
-
(Locked)
Getting started with a new Inertia project1m 58s
-
(Locked)
Creating a Post resource2m 29s
-
(Locked)
Creating the Home and About pages2m 14s
-
Creating an Inertia navigation2m 6s
-
(Locked)
Changing the website title2m 4s
-
(Locked)
Displaying posts3m 4s
-
(Locked)
Creating posts4m 37s
-
(Locked)
Displaying a single post1m 29s
-
(Locked)
Updating posts1m 51s
-
(Locked)
Deleting posts1m 33s
-
(Locked)
Challenge: Show a flash message1m 2s
-
(Locked)
Solution: Show a flash message2m 59s
-
(Locked)
-