Reading Route Syntax0:06
All right, so check this out. In my opinion, one of the truly beautiful things about Laravel is how so much of its API and syntax reflects and mimics how you might speak in real life. And here's what I mean. At this point, we don't know anything about the framework and yet still I can basically parse what's going on here. Let's do it together. Alright, route. Does that represent a route into our application? Yes.
Let's do it together. Alright, route. Does that represent a route into our application? Yes. Yes it does. Alright, get, Hmm? Is that like an HTTP verb? Get post, put patch, delete. Yes. Yes it is. And does this represent the URL or the URI that the person is visiting? Yes. Yes it does. It's the homepage. So in this case we are literally saying register a route that listens or responds to a get request to the homepage. Or in other words, when the user visits the homepage, then
that listens or responds to a get request to the homepage. Or in other words, when the user visits the homepage, then we want to run this callback function and we're gonna load a view called welcome. Okay, so now even if I don't know what that view function does, you can basically guess, right? It loads a view called welcome and a view is the thing that the person views on the webpage. It's the template, it's the HTML, it's the CSS,
Locating the Welcome View1:14
views on the webpage. It's the template, it's the HTML, it's the CSS, it's possibly the JavaScript. It is the thing they read on the webpage. Alright, so very cool. Now I know that by default when I install the framework, I get this route that responds to a request to the homepage and loads a welcome view. Next we can find that welcome view right here In my resources directory.
Next we can find that welcome view right here In my resources directory. We will find a views folder and sure enough, there's welcome. Alright, so this corresponds to the name here. Alright, so let's take a look here. This is the welcome view that you get out of the box when you install the framework. Let's have a look in the browser. All right, so because we are using Laravel herd,
Editing and Reloading Views1:53
Let's have a look in the browser. All right, so because we are using Laravel herd, I should be able to visit our folder name test as I've done here. And sure enough, we see the splash page. All right, so let's just browse around. Let's get started. If I switch back, can I find, let's get started. Sure we can. Why don't we change this to, okay, let's get going. All right, switch back, give it a reload.
let's get going. All right, switch back, give it a reload. And we are updating the view in our layer of help project. Okay? So cool. Now in this case, this is great. It gives you links to the documentation into an incredible video platform. If I do say so myself. However, if you want, you can delete this entirely and replace it with your own HTML. Why don't we say hello world?
Linking to About Page2:37
and replace it with your own HTML. Why don't we say hello world? All right, come back, give it a refresh, and we're up and running. Okay, so now I don't know about you, but whenever I'm learning a framework, I need to know the basics. How do I link from this page to that page? All right, very, very simple. Let's add an anchor tag. And why don't we go to the about page.
All right, very, very simple. Let's add an anchor tag. And why don't we go to the about page. Every static application needs an about page that nobody clicks on. All right, let's do it now about us. Alright, let's go to about us. And sure enough, it did try to visit that URI, but of course we haven't registered a route for about, so we get the standard 4 0 4. This is what we'd expect. All right, let's fix that.
Registering the About Route3:16
so we get the standard 4 0 4. This is what we'd expect. All right, let's fix that. Let's go back to our project, return to our routes file. And I'm gonna copy this and register a new route this time. If the user visits slash about. And a quick little note, you can add the forward slash at the beginning if you want, or you can omit it. Uh, just pick one and stick with it. It doesn't matter. Alright, so in this case, we could load a view called about, or if you just wanted
Alright, so in this case, we could load a view called about, or if you just wanted to return a basic string from this function, you can do so. So you could say about us, alright, come back, give that a refresh and turn enough, it works. Now, most of the time you don't wanna do this, but there are, there are certain situations where it actually can be kind of useful. Okay? Nonetheless, let's return our view and I'm gonna call it abouts.
Okay? Nonetheless, let's return our view and I'm gonna call it abouts. So now at this point, think about it. I see a squiggly line here because we don't have a view called abouts. So if I were to come back and give it a refresh, once again, we're going to see an error. Hey, view called about is not found. So let's do that. Now let's switch back and why don't we just duplicate this and we'll call it about blade PHP
Now let's switch back and why don't we just duplicate this and we'll call it about blade PHP and we'll say about us, we'll change this to return home. And of course that's gonna send the user back to the homepage. Now you can see immediately we are duplicating a lot of, uh, markup here that hmm, doesn't quite make sense in real life, but one thing at a time, I promise we'll get to that. So if I come back and give this a refresh, sure enough, now I'm on the about page and I can return to the homepage.
Homework: Add Contact Route4:43
So if I come back and give this a refresh, sure enough, now I'm on the about page and I can return to the homepage. Alright, so here's your homework and here's your exam. At this point, we've created routes for the homepage as well as about, but maybe folks should be able to contact us. So to get started on that, I'd like you to create or register a new route that listens for get request to slash contact. And in response, I want you to load a view called contact and you can populate it with dummy data.
And in response, I want you to load a view called contact and you can populate it with dummy data. Just for now, I promise we'll get to forms in the future. Alright? So give it a shot, get comfortable and let me know how it turned out.
