Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m

Next lesson playing in 5 seconds

  • Overview
  • Transcript

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.

Back to the top
View on GitHub