در حال بارگذاری ...

Named Routes Basics0:00

This next new addition is a small one, but could be useful in some situations. Imagine that we apply a named route. So, for example, maybe when the user visits admin/home, we'll give that a name, we'll name this route as home, and then just pass a closure directly here, and return some view. Okay, so if I were to run php artisan route:list, sure enough, this URI has a name of home, which means I could say route('home'), and that'll spit out the appropriate URI. But now, if you're going to have a lot of routes within your app namespace, you might want to wrap it within route group.

Grouping Routes with Prefix0:34

the appropriate URI. But now, if you're going to have a lot of routes within your app namespace, you might want to wrap it within route group. Then you could say the prefix should be admin, and then pass a closure here, and nest everything within it. And why don't we keep this a little more consistent. Okay, so now we can remove that entirely, and if we once again run php artisan route:list, well, we still have the same URI. Okay, so once again, nothing new here. But it's possible that in some situations, especially for slightly larger projects, you may want to so to speak namespace your route names.

Namespacing Route Names1:06

situations, especially for slightly larger projects, you may want to so to speak namespace your route names. So, for example, maybe you want this to be admin.home. Well, it's true, you could do this, admin.home, and if I were to run it again, that would work. Or, and here's what's new, if you wish, you can use as directly on route group now. So we could say as, admin, and you can create any kind of delimiter that you want. So if you want it like that, then type admin. If I run that, there you go. So now, to generate a route, you would say

like that, then type admin. If I run that, there you go. So now, to generate a route, you would say route admin.home, and that'll give you the appropriate URI for this one. So if we run that, it works. Or, some people seem to like this convention, then just change it there, it doesn't matter. Then you update it here. And we'll get the exact same thing. Alright, and that's all there is to it for that one. Not a big new feature at all, but it might be useful in some situations.

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