7.2 Displaying the Pages
Now we need to display our pages' content. In this lesson, we'll dynamically build the routes to our pages so that we can navigate to and display them.
1.Introduction1 lesson, 01:23
2.Getting Started4 lessons, 46:41
3.Managing Pages6 lessons, 1:12:31
4.User Management2 lessons, 27:37
5.Managing the Blog4 lessons, 41:51
6.Adding Extras2 lessons, 26:07
7.Implementing the Front-End3 lessons, 30:24
8.Homework Review1 lesson, 07:11
9.Conclusion1 lesson, 01:24
7.2 Displaying the Pages
In this lesson, we are going to display the content of our pages whenever we navigate to them. And we're going to start by creating a view. So let's go to resources, views, home. And let's copy index and rename that copy to simply page.blade.php. And inside of this view, let's just display the pages content. So we will use page and then content. And there we go. So now we need to be able to handle the routes. So that whenever we go to any one of these pages like about page that the routes will be handled. We'll pass the appropriate page to the view and then that would be displayed. Now we could approach this in several different ways. One of them would be to create a catch all route so that whatever was provided as the path would then be provided to a controller and an action method but for something like this, we could use something much, much more simple. And that is to create a route for every page that we have. So if we go to our app. And then providers, there's the route service provider. And if you scroll down a little bit, you're going to see the map method. Now you can see that there is map API routes and map web routes. The web routes are what actually loads the web.PHP file. So we can come in here. And we can set up our routes for our pages by looping over them and then creating an individual route for each page. Now when it comes to actually retrieving our pages, it doesn't matter what order that they are in because we aren't really displaying anything by a particular order. All we want are all of our pages. So we will just call the all method. We want each page as a page. And then whenever we set up the routes, well we could do several different things. But we can also say that there's no logic involved. We have all of the information that we need with our page instance here so we could do something like this. We could say route view. The URL is of course going to be whatever our URL property is. Our view is home page. And then we just need to supply the data to our view. And we have that here. So we can just pass that on then. So that's whenever we go to any of our pages be at the contact page we see the content. You can contact us if we go to about, this is about us and if we go to the fact sheet this is another page. So we now have our working pages. It's very simple, but at this point in time, that's really all that we need. Now if we decide that we need to add some more logic to this or if there's some other functionality that we need to provide or then we can start thinking about moving away from just returning a simple view and handling request with a controller but that's later down the line.