How to Use Rate Limiting in Laravel Rate limiting is a crucial security and performance feature that helps prevent abuse, brute-force attacks, and overuse of your application resources. Laravel provides a powerful and flexible way to handle rate limiting via built-in middleware and custom configurations. π§ Why Use Rate Limiting? Protect endpoints from spamming or brute-force login attempts Ensure fair use of server resources Improve overall API and application performance ⚙️ Using Laravel's Built-in Throttle Middleware Laravel includes a throttle middleware you can apply to routes or route groups. Route::middleware('throttle:60,1')->group(function () { Route::get('/api/data', 'ApiController@getData'); }); This allows a maximum of 60 requests per minute per IP address. π ️ Creating Custom Rate Limiters Since Laravel 8, you can define named rate limiters using the RateLimiter facade ...
Solving the Two Sum Problem in JavaScript Problem: Given an array of integers and a target number, return indices of the two numbers that add up to the target. π’ Input: let arr = [1, 2, 6, 9, 3, 2, 8, 7]; let resultNumber = 10; π§ Brute Force Approach: This solution checks all possible pairs (i, j) in the array. let indexes = []; for(let i = 0; i π Time Complexity: O(n²) – because we check each pair of elements once. π§© Sample Output: [ [ 0, 3 ], [ 1, 6 ], [ 4, 7 ], [ 5, 6 ] ] π‘ Optimization Tip: We can reduce time complexity to O(n) using a hash map. Stay tuned for the optimized version in my next post! ✅ Summary: Clear understanding of nested loops Simple yet effective for small input sizes Ideal for beginners practicing DSA If you liked this post, follow my blog or connect with me on LinkedIn !