تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Handling Missing Doc Content0:00

Alright, let's get back into it. So once again, from our routes file, when we want to show documentation, we hit the DocsController. We scroll down here, we've learned about all of this, so we're now going to continue right here. Okay, so for a refresher at this point content, let's just return that from the controller, switch to Chrome, and give that a refresh, and yeah, we can see it's the original markdown file that has been converted to HTML. So now let's see, if there is no content, so it sounds like in certain scenarios there will be no content at all, and yeah, I guess that's going to be a situation like this.

So now let's see, if there is no content, so it sounds like in certain scenarios there will be no content at all, and yeah, I guess that's going to be a situation like this. So we're going to request something that doesn't exist, yeah, so I assume that's what this is. Now let's see, die and dump the content at this point, does it get that far? Yeah, so I guess it does. Let's see, we check all that stuff, section page, so now we're saying, okay, for the current version, try to get the page for this, but we know it doesn't exist, right, anything we pass there. It's going to try to find it, so for example, if we did, let's just see if this works, for

we pass there. It's going to try to find it, so for example, if we did, let's just see if this works, for 5.6, if we did create a file, excuse me, like so, and if we came back and gave that a refresh, yeah, that does in fact work. However, in the case that you request a page that doesn't exist, that's when we hit this block. So if there is no content at all, then we will return a docs view. So yeah, whenever you come across things like this, you'll learn the basic conventions, right? So here, when I say DocsController, well, when you're getting started, it can help to

Navigating Views Quickly1:38

right? So here, when I say DocsController, well, when you're getting started, it can help to go to app, Http, Controllers, find DocsController, but you already know where that is. So in your editor, just go to DocsController. You don't even have to parse in your head where the file is, and the same is going to be true here. So manually, you would think, well, it's in the resources, views directory, and now I need to find docs. Things like that take up a crazy amount of your time. So instead, always use command P. Okay, so here's the file that's being loaded.

Finding Missing Doc Partial2:25

So now where is it getting the content from? All right, we'll come back. Well, we're getting it from right here. So that's loading another view, partials doc missing. And there it is. There's the main text we've been looking for. So it's interesting, in this case, I assumed originally that this would be the default 404, but it looks like, in fact, that is not the case. Let's see, do we even have anything for 404? We do.

Okay, I got it. So we'll come back. It's sending through some basic data. So let's see. I guess the information it'll need, the current version, getDocVersions. Okay, that's a list of all of the versions. So I assume that's just to populate some of the stuff like this, it still needs. Okay. Now, if it's not null though, so let's imagine we've requested a page that does in fact exist. Well then, we're to this point.

Extracting Title with Crawler3:30

Now, if it's not null though, so let's imagine we've requested a page that does in fact exist. Well then, we're to this point. Now what's going on here, the title? So we're creating a new crawler. This is something that Symfony provides. It allows you to basically filter through a block of HTML. So if you want to say, in this case, give me that h1 tag, or give me this link, it's just an API to help with filtering HTML. I've used it in test tools that I've created in the past. Anyways, so I guess what's happening there is, it's going to open up, let's see, in the

I've used it in test tools that I've created in the past. Anyways, so I guess what's happening there is, it's going to open up, let's see, in the docs, it's going to open up this file, or at least the compiled version of this file. And it's going to grab the h1, whatever gets converted to an h1, there it is. So it's grabbing that right there. So in fact, if I were to say authorization, that, I assume, is what will be saved as title. Refresh, and whoops, yeah, we have the crawler instance. Let's just grab the text, the inner text, and sure enough, we do get authorization. Okay. Now, where is that being used?

Okay. Now, where is that being used? So I'm going to skip this for just a second. So here's where we load the main docs view. So before, if the content was null, we still loaded this page, but then we gave it the custom 404, basically. But now we're loading it once again with the proper content. And you'll see content has been substituted there. Okay. So title, we're saying if the crawler returned items, essentially, then grab the inner text,

Rendering Title in Layout4:57

Okay. So title, we're saying if the crawler returned items, essentially, then grab the inner text, otherwise set that to null. Anyways, where is the title being echoed out? Hmm. Okay. So I assume it's going to be in the layout file. So let's see, app.blade.php, where is the title? And there it is. So within the head section.

And there it is. So within the head section. So if there is a title, so remember, in some scenarios, it could be null. So we do a quick check. So if there is a title, like authorization, then it will be title dash, and then Laravel PHP Framework for Artisans. Let's confirm that. Here's our title, and sure enough, that's working. Okay. That works.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟