Finding Splash Page0:07
Now one thing I've noticed is that I can't seem to find in Jeremy's repository the original splash page that people see when they visit our site for the first time. And I know Simon implemented that. But if I take a look in the views directory, welcome is just the Laravel welcome page. So it's possible that he skipped over that because it's mostly static. Uh, but nonetheless, I do wanna implement that. So let's do that together.
Uh, but nonetheless, I do wanna implement that. So let's do that together. Let's go to Simon's, uh, repository. And it looks like he put it within index.html and yeah, this is that splash page. So I'm gonna grab the raw code here and let's go into our routes file. And yeah, you'll remember temporarily we were just redirecting the homepage to the loggedIn view, but we're not gonna do that anymore.
Creating Home Controller0:52
redirecting the homepage to the logged in view, but we're not gonna do that anymore. So let's listen for when you visit the homepage and let's see, did Jeremy implement any kind of PagesController? It doesn't look like it. So let's keep it simple. Let's just create, um, a simple one called HomeController. Alright, so let's create that Now, php artisan make:controller HomeController. It's gonna be invo, meaning this is a controller
php artisan make:controller called HomeController. It's gonna be invo, meaning this is a controller that will only ever have a single action. So I can bring that up, import that switch over, and this can be home splash page. All right, let's see if that works in the browser. And yes, it does. If I visit the homepage, it's working. So now we're going to return Inertia::render, and let's just call it home. All right, so within the pages folder, home.blade.php
Building Home View1:42
and let's just call it home. All right, so within the pages folder, home view, and as we've done in the past, let's load our layout like so let's do it once again. Sanity check. Give it a refresh. Yep. Homepage. Okay, so now I can paste in all of that markup that Simon created. And there's a bunch here. So I think I'm gonna have to clean a lot of this up. Yeah, quite a bit here. And we don't need any
So I think I'm gonna have to clean a lot of this up. Yeah, quite a bit here. And we don't need any of this or the head. I'm not sure about the body. I'll get rid of that. And then the same down here. Okay, see how we're doing? And actually, yeah, this looks reasonably good to me, but my guess is, um, this isn't supposed to be included on the marketing page, right? So maybe we can get rid of the layout entirely.
to be included on the marketing page, right? So maybe we can get rid of the layout entirely. Yeah, maybe we don't need that at all for the homepage. And then yeah, we just have some alignment stuff that we could fix. So what you can do is, uh, let's return the main classes that were on Simon's original wrapper. So like if I paste that in, that's, I'm just copying and pasting that from what we got on GitHub. Now the alignment, um, is correct.
and pasting that from what we got on GitHub. Now the alignment, um, is correct. Okay, so now in terms of the forms, yeah, like I said, I don't think they worked on the layout for any forms and that's not, that's not included with my section here. So I think we're just gonna follow what Jeremy did. When you click on signIn, we're just going to mock it basically. And honestly I think that's okay. You have learned how to create an account.
And honestly I think that's okay. You have learned how to create an account and how to register and countless videos across Laracasts, do we really need to do it all over again? So if I switch back, alright, so let's see what we have here. Sign in with Google, we're skipping that. Create an account, would maybe go to a register page. Sign in would go to your login route, right?
Sign in would go to your login route, right? So if I were to come back, if I click sign in, that will hit the login route. And don't forget that Jeremy stubbed that. And that just quickly creates a User, logs them in, and then redirects, um, to, to the profile page. All right, let's give it a shot sign in. Redirects me to my profile page. Now, actually while I'm here,
Hiding Self-Follow Button3:50
Redirects me to my profile page. Now, actually while I'm here, I just saw something kind of funny. Uh, we forgot to handle the possibility that you might try to follow yourself in the follow episode. We didn't account for that. So notice this is me, but there's still the option to follow. Now this was handled on the backend, so if I try to click follow, we're gonna get an authorization
Now this was handled on the backend, so if I try to click follow, we're gonna get an authorization or I'm sorry, a um, an exception because a Profile cannot follow itself, but nonetheless, I shouldn't even reveal the button in that case. So this will only take me 20 seconds. Let's go into ProfileHeader. And right down here, this is our follow button. So let's say only display this link.
And right down here, this is our follow button. So let's say only display this link. If the profile's id is not the current user's profile. It seems like that's how Jeremy's doing it. Everything goes through the profile rather than the user. So if the profile's id actually, real quick, do we have an id? No, I think it's okay if we send that through. I don't think that's overly private. Um, but then check if the profile's id does not equal the
I don't think that's overly private. Um, but then check if the profile's ID does not equal the current user's profile id. And one thing to keep in mind is, is it possible to look at, uh, well actually hold on, let's make sure this works. Yeah, now I don't see it, but if I go to a different account, um, right here I do see it. Okay, so that works. But also we need to decide, uh, is the feed and the profile page, is that
Handling Guest Profile Views5:08
Okay, so that works. But also we need to decide, uh, is the feed and the profile page, is that behind the authentication wall? Or can a guest visit? Because if a guest can visit, then we gotta structure things a little bit differently. Right now it seems to me, is this all behind an auth middleware? Let's see what we have here. This null, anyone can view the profile.
Let's see what we have here. This null, anyone can view the profile. Okay, that's really important information because if I now try to access this page and I'm not signed in, well of course it's going to throw an error because we're accessing profile.id off of null. So maybe we do something like this or we can have a check like, well, are we signed in off user?
or we can have a check like, well, are we signed in off User? Um, or if you want, you can even do something like isSignedIn. You add a little, uh, a little helper there, uh, within handleInertiaRequests if you're signed in and then move to the right side. Um, so that would be an option, something to think about. Okay, but finally, last little thing I can return to the homepage.
Restricting Homepage to Guests6:09
Okay, but finally, last little thing I can return to the homepage. Do we want that or is that something where, you know, you only ever see this if you're not signed in. If you are signed in, we immediately redirect you to your feed and that's probably what you want. So in that case, we go to our routes file and at the very top we say auth->middleware, uh, you gotta be a guest in order to access this page. Otherwise it's going to redirect you to your home route.
you gotta be a guest in order to access this page. Otherwise it's going to redirect you to your home route. So now if I come back, yeah, it already did it, but if I access the homepage again, it instantly redirects me. But if we visit dev/logout, then it logs us out. And actually this wasn't handled properly, but um, if we go to the homepage, we can see it again. All right, let's see. dev/logout. Nope, this isn't right. If you log out, we're going to redirect you back home.
All right, let's see. Dev Logout. Nope, this isn't right. If you log out, we're going to redirect you back home. Redirect to the homepage. But yeah, it doesn't matter 'cause this is all temporary in the first place. Okay, so now we have the homepage in place. We have your feed, we have your profile, the show page. I think we're making really good progress. We're about to wrap this thing up.
We're about to wrap this thing up.
