Reviewing Routes Overview0:00
Now, whenever I review a new Laravel project, almost always, the first thing I do is look at the routes. This gives you a quick bird's eye view of what sort of things this application can do and what it can respond to. So immediately I can see, alright, there's a marketing page, basically a static landing page I'd assume. We have the documentation, then a page for the various partners, these are all different partners, and that's it. So very, very simple. So let's begin right at the homepage.
So very, very simple. So let's begin right at the homepage. The homepage loads a marketing view, which is this. Okay. Well, as we know, that will always be in resources/views, and then there's Marketing. Okay, so we can see a bunch of HTML here, and you know what, mostly we're not really focused on this side. If there are certain things you want to learn about, like how are they doing the dropdown here, are they using something like Twitter Bootstrap for that, if you're curious about the syntax highlighting, sure, you can take a look at that.
Docs Routes and Redirects0:46
here, are they using something like Twitter Bootstrap for that, if you're curious about the syntax highlighting, sure, you can take a look at that. But mostly, like I noted, we're focused on the documentation layer. So you can see it takes us to Docs/5.6. Okay. So it looks like we have two endpoints, one for Docs and then another one for Docs slash the framework version, and then also a page, which is optional. Okay, so let's see what happens when we hit Docs. Ah, it still loads the version. So let's see what's happening there.
Ah, it still loads the version. So let's see what's happening there. Now I see right here, if not defined default version, it will create that. Okay, so I assume every time a new framework version is released, this is updated. So when 5.7 is out, this will manually be changed. Okay, so let's see. When we load /docs, it's going to hit this DocsController at showRootPage. So let's go to that DocsController, and then we should have a showRootPage view. And it looks like all that does is it redirects to docs slash the defaultVersion. So that's doing a redirect to docs slash 5.6 in this case.
And it looks like all that does is it redirects to Docs slash the default version. So that's doing a redirect to Docs slash 5.6 in this case. Okay, so that explains this. Let's come back now. That's now hitting this route. So Docs slash a version slash a page will hit DocsController at show. Okay, so let's go to the show method. And just for proof, we can say reload, and we are hitting that action. Okay, so right off the bat, let's take a look at what this is doing. So a fairly sizable method here.
Validating Version and Page2:15
Okay, so right off the bat, let's take a look at what this is doing. So a fairly sizable method here. I'm on a low resolution, but mostly, we're loading a view, building up some data, checking for content. Yeah, let's look over all of this. Okay, so step one, if not isVersion, so the version number is 5.6, right? So we're saying if that's not a version, so I assume that's saying like, well, what if you request 6.3, and that doesn't exist? Well, you notice it looks like that does a redirect to 5.6, and then the version. So it does a redirect to Docs.
Well, you notice it looks like that does a redirect to 5.6, and then the version. So it does a redirect to Docs. So if you request a Laravel framework version that doesn't exist, it does a redirect to Docs slash the default version, so 5.6, and then it takes the version. So in this case, we typed in 6.2, and it appends that on. So you know what I bet? It's checking to say, okay, if what you did was reference a specific page here, like let's look for installation, I assume it's saying, well, if you go to Docs slash installation, it's going to redirect you to the latest version of that page. That's what this is doing here.
it's going to redirect you to the latest version of that page. That's what this is doing here. Does that make sense? So you go to Docs/installation, it then says, is it not a version? So let's imagine we're going to check installation. All right. So is installation in this array, and it looks like it's getting the keys from documentation::getDocVersions(). Okay. Well, of course, at the top, we can see documentation is in the app folder.
Okay. Well, of course, at the top, we can see documentation is in the app folder. Okay. So what is the method we're calling here? getDocVersions. Okay. So it's getting a key. So this is a list of all of the Laravel versions, or at least all of the supported versions. So 4.2 all the way up to the master branch. So now at this point, you can see, well, is installation in the list of keys that you
So now we understand at the very least for any page, you don't have to go to the version number. You can just go to Docs slash whatever the page is, and it will automatically do a redirect to the latest supported version. Great. So we understand that. Next, if not defined, the current version. Okay. So there's a default version, which is 5.6 at the time of this recording. But then we're also checking for the current version that you are browsing.
And we talked about that a little in the last episode. But nonetheless, I assume in this case, it's checking, okay, you want the 5.2 documentation, so we're going to store that. So let's dd current version just to be sure. Refresh. And yeah, that's storing that for future use. Okay. Next up, the section page. So that's figuring out, you can see right here, if we go back, so you go to Docs/version/5.6 slash the page that you want, like installation or deployment, any of those
So that's figuring out, you can see right here, if we go back, so you go to Docs/version/5.6 slash the page that you want, like installation or deployment, any of those pages in the Laravel documentation. So it looks like it's saying, okay, well, the page is optional. So if you don't give us anything, we're going to go to the installation page. Let's confirm that. If I come back, and once again, we'll go to /Docs, yeah, you can see by default, it's loading the installation page. Let's go to maybe we want to visit releases by default. Then we could change that.
Loading Markdown Content5:53
Let's go to maybe we want to visit releases by default. Then we could change that. All right. Once again, 5.6, and now it immediately takes us to the releases page. Okay. So we know how that's working now. Next, yeah, this is what I'm interested in. So how does it fetch the contents? So for example, once again, how is it getting all of this stuff? Because we know from the last episode that it's stored within resources/docs.
So for example, once again, how is it getting all of this stuff? Because we know from the last episode that it's stored within resources/docs. So if we go to 5.6, is there an installation page? Yeah. You can see all of this is stored as Markdown. So notice the layer of our framework has a few system requirements, yeah. So let's see, is that being cached by any chance? So let's just say like that, come back, refresh, and it's not being reflected. So I assume what's happening behind the scenes is so that you don't have to parse this over and over.
It will then throw it into the cache. And that way for future uses, it just fetches it out of the cache and it doesn't actually have to load this file. Okay. Let's figure out how that's working though. So we're saying this docs get 5.6, and then in this case, installation. Okay. What is docs? So at the very top, we can see with this constructor injection, we're accepting a Documentation instance.
Caching Docs via Class7:25
So at the very top, we can see with this constructor injection, we're accepting a Documentation instance. And Documentation is within the App namespace. There it is. So we can see Documentation, it's not an Eloquent model, it's just a, it's a POPO, it's a plain old PHP class. So if we call get, there it is. So we can see it is using the cache driver behind the scenes. Okay. So we're saying this cache, remember, docs.version.page.
Okay. So we're saying this cache, remember, docs.version.page. Okay. So every page is going to be cached with a name of docs, in this case, 5.6.installation. That is the key that's being used. So we can confirm that. Let's go back to installation. We will change this back to a period. But if I come back and give it a refresh, of course, it's still in the cache, right? So now, let's clear the cache, php artisan tinker.
Installing Tinker for Cache8:10
But if I come back and give it a refresh, of course, it's still in the cache, right? So now, let's clear the cache, php artisan tinker. Oh, command tinker not defined. Oh, yeah, wasn't, this may not be updated to reflect that. Let's see. Laravel framework 5.6. If I remember correctly, tinker was extracted to its own package. Let's take a look at that really quick. Laravel framework, composer.json. Was there something for tinker?
Laravel framework, composer.json. Was there something for tinker? Yeah. And you can see that's suggested. Okay. So let's do a composer require to pull that in. There we go. Now, hopefully, it'll auto-register. It does. Great.
All right. So let's see. When we get documentation, we wrap it all in a cache column. So just to make it easier, let's comment that out. And now this is basically what we're doing. So it's figuring out the path to the documentation page. And you can see it's just concatenating that. So it's saying look in the resources/docs folder, all right, into the version folder 5.6. So you can imagine if we cloned in 5.5 documentation, 5.4, we just went to the GitHub repo and we
5.6. So you can imagine if we cloned in 5.5 documentation, 5.4, we just went to the GitHub repo and we cloned in every different version. Well, when you request the 5.2 page, we look in that folder instead of 5.6. Okay. And then it looks for the page.md. So in this case, for installation, it's going to look for, where is it, installation. It's grabbing that file. Let's dd just to be sure, refresh, and there you go. You can see it's looking exactly for that file.
Let's die and dump just to be sure, refresh, and there you go. You can see it's looking exactly for that file. Next, it's saying, okay, well, if that file exists, because what if you requested something that doesn't exist? Like that. Well, actually, real quick, let's bring back the die and dump. Yeah, now it's going to look for foobar.md and it doesn't work, but let's see if we could make it work. So we'll create a new file, foobar.md, and let's just grab some of this, paste it in, and we'll say, ooh, that's a lot, we'll say foobar docs.
So we'll create a new file, foobar.md, and let's just grab some of this, paste it in, and we'll say, ooh, that's a lot, we'll say foobar docs. Okay. Now, I think that should work. So if we give it, I'm sorry, if we come back, get rid of that die and dump. Anyways, if we give that a refresh, now you can see how it would load a new documentation page. Very cool. So finally, if the file exists, then replace links with markdown. Okay.
So finally, if the file exists, then replace links with markdown. Okay. I'm not entirely sure what's happening there. So we're going to bring this back to how it was before, and then in the next episode, we're going to take it from there.
