Recap Custom Blade If0:00
Now, several episodes ago, we've reviewed custom Blade if conditionals. So we learned that in your app's ServiceProvider, you could do something along the lines of this. We could say blade if, and now this could be anything, like if you're signed in, or if you're subscribed, anything that can return a Boolean. So maybe you want to check the environment. Well, we could define it like so, and then yeah, here we could just say return, and then check if the app's environment is equal to what you pass in. And that's it. So now, this is just a very quick recap, but now I'm in my welcome view.
Testing Environment Directive0:28
And that's it. So now, this is just a very quick recap, but now I'm in my welcome view. Let's clear all of this junk out, like so. And yeah, now we could say, well, I'm going to use my new Blade directive, and we'll say if the environment is equal to local, you are in the local environment. So now, if we view this in the browser, sure enough, we're in the local environment. But if we switch over and we change that to something like production, well, of course, we won't see anything. All right, so that's a quick recap. But now, also new in Laravel is a couple helpers that follow the same format.
Using Built-In Guest Directive1:02
All right, so that's a quick recap. But now, also new in Laravel is a couple helpers that follow the same format. So if we switch back, let's just delete that. And now in our welcome view, well, you'll remember several episodes ago when we talked about these custom Blade if conditionals, we set up some like guest. So if the User is a guest and not signed in, then proceed. But as it turns out, since I've recorded that video, the framework later added support for these. So that means I could say end guest, and yeah, we don't have to implement this ourselves. You get this straight out of the box.
Signing In User1:52
Now that's been shortened. All right. So let's say else. You are a guest. You are a member. All right. Give that a refresh. And once again, we're a guest. But let's sign the user in here. So let's just say auth login.
Auth and Guest Helpers2:04
But let's sign the User in here. So let's just say auth login. And I need a User, but I don't have one. Let's just whip one up really quick, app\User::create. Yeah, just whip up a generic User and then sign them in. All right. So now if we come back and give it a refresh, sure enough, we are a member. And that's it. That's all you need to know for this video. So two helper directives have been added, one for auth and then one for guest.
That's all you need to know for this video. So two helper directives have been added, one for auth and then one for guest.
