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

Configuring Default Fallback0:00

We learned in earlier videos that Valley configures dnsmasq to capture all requests that are made to our .test domains, but what happens if you request a domain and there's no folder to match it? By default, you're just going to get a 404 page. However, you can customize the site that shows when Valley displays you a 404 if you want. Sort of like an old-school new tab page, you can tell Valley what to show any time you type anything.test. To define this, open up your Valley config file at config-valley-config.json and add a new key called default. The contents of that key should be an absolute path on your file system.

a new key called default. The contents of that key should be an absolute path on your file system. We'll point it right now to a site named Fallback that I created just a bit ago using laravel new. And maybe this could be helpful for you. You can possibly want a Laravel app to take certain steps every time you type fake-site.test or whether it's to actually create a site at that domain or insert something in a database somewhere or who knows what. Either way, let's take a look. If we refresh now, we get that blank Laravel app that's serving from Fallback.

Either way, let's take a look. If we refresh now, we get that blank Laravel app that's serving from Fallback. And if we were to go to that site, we can just edit the welcome page to show that this is the actual site that we're seeing. So you can see we've got our yay Fallback there, even though we're at abc.test. But one thing I think is really interesting is that you can include Valley as a composer dependency in your Laravel apps. I just built this recently, so it's pretty early access and not much has been done with it. But it's really cool that you can run all the methods that power Valley, like asking

Requiring Valley in Laravel1:45

it. But it's really cool that you can run all the methods that power Valley, like asking for a list of sites you have parked or securing a site, all directly from the Valley composer package. So let's take a quick look at how to include Valley in your Laravel app and imagine some things you might do with it. First of all, let's require Valley in this site. So composer require laravel/valley. Next let's open up one of our routes and grab a Valley class. Valley Site class, which we'll get started with, is what we use to get a listing of all

Listing Parked Sites2:12

Next let's open up one of our routes and grab a Valley class. ValleySite class, which we'll get started with, is what we use to get a listing of all your sites. So let's just use Valley::site. Let's make an instance of that class. And let's just get the parked method to see all the sites that we have that came in through being parked. Let's take a look. Now we can see these are all the sites we have that are parked through our sites directory. With each of these sites, we can do some interesting things.

Now we can see these are all the sites we have that are parked through our sites directory. With each of these sites, we can do some interesting things. We can see the name of the site, whether or not it's secured, its URL, its full path, and the php version that it's working with. There's all sorts of interesting things you can do here. But also, what if you wanted to change something? Let's say there's a route where if you visit it, it will secure a site. Let's say fallback.test/secure/fallback or fallback.test/secure/floga or fallback.test/secure/my-new-site secures the site that you're passing in. Something like this, fallback.test/secure/floga, and that would secure it.

Exploring CLI Commands3:21

secures the site that you're passing in. Something like this, fallback.test/secure/floga, and that would secure it. You can do that. This class is not just limited to read-only commands. So the big question here is, how do you know which commands to run? Let's take a look at the Valet codebase really quickly. In the Valet codebase, there's a file that is cli/app.php, and this is what defines all of the actual commands that you can run from Valet. You can see the status command here. You can see the install command here.

You can see the status command here. You can see the install command here. So what you can do is find the command that you're interested in replicating if you're playing in this code and see how it works. If you want to do something with the TLD, see how it works here. So if you wanted to secure it like we were talking about there, you just find the secure definition here. It literally just takes what's passed in and turns it into a full URL and then passes it into the siteSecure method. Now, you might have to do a little bit of digging, like what's the outcome of the site

Building a Sites View4:19

into the siteSecure method. Now, you might have to do a little bit of digging, like what's the outcome of the siteDomain method? What does expire in if I wanted to customize it? What is this 368? Is that days, hours, minutes, or whatever? But in general, you can see all the syntax you need to know what it would look like to make your own call to siteSecure in your own Laravel app. So let's build something just super quickly to see what we can make it look like. Let's come over here and instead of dying and dumping on parked, let's pass it into

So let's build something just super quickly to see what we can make it look like. Let's come over here and instead of dying and dumping on parked, let's pass it into the welcome. And then I've got a really quick view here called welcome with parked. And basically what I did in here is I iterate over every single one of the sites, I make a link to the URL, and then I show the text for it. That's it. So let's take a look at how that looks. Great. So now we can see all of the sites that we have parked, we can click on each one and

Great. So now we can see all of the sites that we have parked, we can click on each one and go to it directly. Now this is missing some of the complexities of how sites work. For example, it's not showing us anything linked or anything like that. But this has taken us pretty decent way. And one of the things I'd started doing at one point on a stream was building out a version of this where each of them would say what version of php they're running on and what version of Laravel they're running on and what driver they use so that we could actually potentially build something like this.

version of Laravel they're running on and what driver they use so that we could actually potentially build something like this. And I'll probably keep working on that. But I just wanted to show you the possibilities that you can come up with if you want to do something. And you can add buttons next to every single one of these, you can make a button that says, I don't know what else you might want to do with it. You know, you can secure it, you can do valet specific things, but you can also do other things that are relevant to you. The valet fallback world is your oyster.

Key Takeaways Recap5:46

things that are relevant to you. The valet fallback world is your oyster. So key points here. Number one, you can set a default fallback site that shows every single time you try adopt test domain that has no match. And number two, you can use composite or require valet to do all sorts of interesting things based on your valet local install.

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