00:00
So when you first opened up that link, that URL that the server is running
00:05
on when we ran the composer run dev command, that's 1 2 7 0.0 0.01.
00:11
This is on port 8,000.
00:12
You're greeted by Laravel friendly default welcome page at least for
00:17
Laravel 12 at the time of this recording.
00:19
And when we take a look at our code, that's thanks to this route in route,
00:24
and that's that directory web php.
00:27
It looks like this.
00:28
And this little bit of code tells Laravel when someone visits, thanks to
00:33
this route facade, when someone visits the homepage, the slash route, we're
00:38
going to show them this welcome view.
00:41
And again, since I'm using VS code with the official Laravel extension,
00:45
I can have this option click to be able to follow that welcome view
00:50
to this welcome do blade dot php.
00:53
This is where that web PHP route is saying, when a user goes to slash or the
00:59
route directory of your application, we're going to return the view that is welcome
01:05
and that's what this view looks like.
01:07
Let's make some changes.
01:08
Let's update this to, um, let's say the home route.
01:12
I'm going to save that and because I have the VS code extension,
01:15
it is actually giving us an error right here in the editor.
01:18
The view home is not found, and if we were to open up our application,
01:22
we get that same server error.
01:24
This view home is not found.
01:27
So what can we do about this?
01:29
And again, if you're using the Laravel vs code extension, not only does it tell
01:32
you that this view cannot be found, but it also gives you an easy way to fix
01:37
this, to create a new Home Blade PB file.
01:41
But we'll do that by hand for everyone following along in our views directory.
01:46
We're just going to create a new file and I'm gonna call this Home Blade pb.
01:52
Now we're not gonna get an error anymore, but if I was to go
01:55
back, it's just a blank page.
01:57
So why don't we go ahead and create this home view now I'm just going to paste in
02:02
the entire code so that we can get this up and running as quickly as possible.
02:05
And we'll walk through a step by step if you're following along on the Laravel
02:08
Learn page, you can find it below this lesson if you're not following
02:11
along on the laravel.com/learn page.
02:15
That's a great place to find this code.
02:18
Now a couple things to note is that Blade is just HTML.
02:23
We could have a whole script tag in here if we wanted to,
02:27
or we could have a style tag.
02:29
Everything that you see in this file is just HTML Blade, just has a little
02:35
bit of templating on top of that that we can get into in a little bit.
02:40
Now for this application, we have a couple of things that we are giving
02:42
you out of the box, even on top of what Laravel already provides, just to make
02:47
things a little bit easier and keep the focus on what Laravel does and how we can
02:52
build applications with Laravel and less about styling and everything like that.
02:58
Laravel already gives us tailwind CSS out of the box and it's set
03:02
up for our application to use.
03:05
So when I go into this home directory, what's happening is when we use this at
03:10
VT directive, we are saying we want to use the app, CSS file, and the app js
03:16
and again, just to keep things as simple as possible, focusing on Laravel
03:20
itself, we're including Daisy UI as one of the links that we're bringing in.
03:26
Mostly to be able to have, uh, some styles out of the box.
03:30
It uses Tailwind CSS, so we're just building on top of
03:33
what Laravel already gives.
03:35
You can see here that we have this data theme of lo-fi that is Daisy ui,
03:40
Now that we have that saved in our code editor, if we go back to our
03:43
browser, we should see the yes.
03:45
Now updated chopper.
03:47
So it's starting to look a little bit better, but this is where
03:51
all the fun actually begins.
03:54
We have this HTML file here, our home blade php, and you can imagine this
03:59
would get a little bit complex because if we were to use additional pages,
04:04
like say a sign in or sign up page, we would copy everything and then add it
04:09
to a new sign in page and then change the things that we needed to change.
04:14
But then if something small changed, we needed to change on everything.
04:18
This is where blade layouts, or in this case a layout
04:22
component that is a blade file.
04:24
This is where those come into play.
04:26
You can take your content from these views, and then that gets injected into
04:31
the layout via this special slot variable.
04:35
It looks something like this.
04:37
And so what we're going to do is we're going to create a new layout component to
04:41
take everything here, let's say everything in this main div and push it into a slot.
04:46
So any new page that uses that layout then automatically gets all of.
04:51
This extra stuff attached to it.
04:54
what we can do is in our resources folder, in our views, we're gonna
04:59
create a new folder, a components folder, and in that components folder,
05:05
this is what Laravel looks for.
05:08
We're gonna create a new layout blade php.
05:12
Now, for right now, I'm just going to copy all of this and
05:15
put this in layout blade PP.
05:19
And in this main class, I'm gonna take this out and add this slot variable.
05:28
So in that way, any time we are using this layout, blade pb, it's
05:33
going to use all of this, including the HDML document, the head, the
05:39
vet, as well as any other additional things that we add to this file.
05:44
And it's going to pass it in to this slot.
05:47
So basically any other stuff that we add to a file in this
05:51
layout will be put right here.
05:54
So that's what we're gonna do in home.
05:56
Um, we're just going to take all of this, actually, let's just
05:59
copy this within the main diviv, I'm going to replace everything.
06:05
We're gonna say X dash.
06:08
And then I'm going to paste everything in X layout, and this is wrapping this up.
06:14
Now Laravel knows to look for a layout in the views components
06:21
directory, and you can see here that the Laravel extension automatically
06:25
says that, Hey, this is valid.
06:27
so if we were to look at our browser, we shouldn't see any change because
06:31
we just kind of took this one file and made it into two files to make
06:35
it more composable in the future.
06:37
And yeah, we, if we refreshed even, we still had and have this application
06:43
looking exactly how we expect.
06:45
We're gonna do one more thing in our layout.
06:49
We're going to make this title a little bit more composable instead of something
06:55
that is hard coded into this file.
06:59
we're actually going to use some PHP here to say, okay, if this title
07:07
variable, and we will get to what this looks like in a little bit.
07:11
If it's set, let's use the title.
07:13
If not, let's just revert to chirp.
07:18
And what this is going to do is now we can set this prop of title in our layout
07:24
where we're using that in our home.
07:25
Okay, what does this look like?
07:29
Well now we have this X dash slot variable allowed where we can pass it, the title
07:35
and say, we're just going to use welcome.
07:37
So if I was to save this and go back to our browser refresh.
07:41
Here in the browser we see that title.
07:44
If I was to change this to something else, such as, hi there, bootcamp.
07:49
We should see exactly the same thing.
07:54
I'm gonna change it back to welcome.
07:56
Next to start setting up our application for a little bit more composability
07:59
in the future, we're gonna add some styles to our app CSS file.
08:05
You can find these in the Laravel Learn page for this course lesson.
08:10
And pasting this in.
08:11
This is just a way for us to have a fade out animation.
08:15
That way we don't have to think about this later when we set up notifications.
08:19
And this is Tailwind Cs S'S V four.
08:22
Way of doing this within an application.
08:25
With all this in mind, we now have an application that is
08:28
ready to start adding pages.
08:30
We just have to use this X dash layout in order to get everything that we
08:34
would expect within our application.
08:36
This nav, a footer, and then a simple layout to be able to add things here.
08:42
We're ready for the next lesson.