In Part-6 of Laravel 6 Basics, we will continue learn about Routing in detail.
We will keep experimenting with lot of route functionalities in new Laravel 6 website and in E-com series.
In this video, we will learn about Fallback Routes, Rate Limiting and Accessing The Current Route.
Fallback Routes
Using the Route::fallback method, you can define a route that will be executed when no other route matches the incoming request instead of 404 page that typically called in such cases.
If user call some route like
http://127.0.0.1:8030/aaaa that does not exists then instead of showing 404 error page we can return the user to predefined route that we will call with fallback route as shown in video.
Rate Limiting
We can set the limit of any route so that the user can only access to limited number of times. We can assign limit to one or any number of routes specified in middleware route group. We will use throttle with middleware that accepts two parameters that determine the maximum number of requests that can be made in a given number of minutes.
For example, let's specify user-info route in user middleware route group that can only run 10 times per minute. For first 10 times, Access Available message will come and after that "429 Too Many Requests" error will come.
Dynamic Rate Limiting
We can set the limit dynamically also from User model with rate_limit attribute but it is not mentioned anywhere how to pass this from model.
Distinct Guest & Authenticated User Rate Limits
We can specify different rate limits for guest and authenticated users. For example, we can specify a maximum of 3 requests per minute for guests and 6 requests per minute for authenticated users.
Accessing The Current Route
You can use the current, currentRouteName, and currentRouteAction methods to access the current route.
Тэги:
#laravel_basics #laravel_6_basics #laravel_routing #laravel_routes #fallback_routes_laravel #rate_limiting_laravel #access_the_current_routes_laravel #laravel_6_basic_routing #dynamic_rate_limiting_laravel #distinct_guest_user_limits_laravel #authenticated_user_rate_limits