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

Introducing Route Helpers0:00

Okay, next up we have a few route-specific helpers. So let's switch over to Sublime, and we're going to review route redirect and route view. So you know what, let's do this. Let's go ahead and run php artisan make:auth, and if you're familiar with this command, that will quickly scaffold an authenticating layer. It'll have your registration form, your sign-in form, all of that stuff. Now you can see in this case I'm already signed in, but of course if you weren't signed in you would see login register links there. Okay, anyways, here's our home route, but sometimes you will want to redirect one route to another. So for example, if we switch back, this is what that command added. Anyways, maybe you want to say, well, if the User visits your website /me, that should take them to their dashboard, right? So traditionally what you do is something like, well, if the User visits /me,

Using route redirect0:39

you want to say, well, if the User visits your website /me, that should take them to their dashboard, right? So traditionally what you do is something like, well, if the User visits /me, then we're going to do a redirect to /home. Pretty standard stuff. Now if we come back, give it a refresh, I'm going to visit /me, and sure enough, it redirects us to the home page. Okay, but now in Laravel 5.5, this has been streamlined just a little bit. So now I could say route redirect me to home, and yeah, it just simplifies things a bit. So anyways, now if we come back and we visit /me again, you're going to get the exact same thing, but yeah, that's just a cleaner approach, I would say. Okay, so that's route redirect, but on that same wavelength, we have route view as well, and that'll be for this sort of use case, where you have a route and all you want to do is just return a view. And this is common for

Using route view1:23

but on that same wavelength, we have route view as well, and that'll be for this sort of use case, where you have a route and all you want to do is just return a view. And this is common for page-specific URLs, like an about page, where there's not much data, it's not dynamic, it's just when the user visits this URI, load that view. So with that in mind, I could say route view. So when I visit the home page, I want to load the welcome view, and now once again, I can get rid of that. Okay, so let's come back, go to the home page, and yeah, we see the exact same thing as we had before, but yeah, just a more simple, more terse approach. All right, and that's all you need to know. So in your projects, in Laravel 5.5, you can now leverage route redirect and route view.

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