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

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