Skip to main content

Posts

How to Use Rate Limiting in Laravel

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 ...
Recent posts

Solving the Two Sum Problem in JavaScript

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 !

How to Use Ngrok for Your Local Project

How to Use Ngrok for Your Local Project When you're developing a project locally, sometimes you need to expose it to the outside world — for testing webhooks (like Stripe, RevenueCat, Razorpay), sharing work with clients or teammates, or testing mobile apps. That’s where Ngrok becomes incredibly useful. πŸ” What is Ngrok? Ngrok is a tool that creates a secure tunnel to your localhost. It provides a public URL that maps to your local web server. It's perfect for testing APIs, webhooks, or sharing local work without deploying it. πŸ› ️ How to Install Ngrok Download it from the official website: ngrok.com/download # For Linux/macOS: unzip ngrok-stable-linux-amd64.zip mv ngrok /usr/local/bin # For Windows: # Unzip and run ngrok.exe from CMD or add it to your PATH πŸš€ How to Use Ngrok with Your Project 1. Start Your Local Server For example, if you're running Laravel or Node.js on port 8000 : php artisan serve # O...

How to Integrate RevenueCat Webhook in Laravel

How to Integrate RevenueCat Webhook in Laravel If you're using RevenueCat to manage in-app subscriptions for your mobile app (iOS, Android, etc.), it’s important to connect it with your backend. Laravel makes it easy to handle incoming webhooks for real-time events like purchases, renewals, cancellations, and more. πŸ“Œ What is RevenueCat? RevenueCat is a powerful subscription management platform for mobile apps. It simplifies in-app purchases across iOS, Android, and Stripe. With webhooks, it notifies your server in real-time when important events happen, such as a new purchase or a cancellation. πŸ”— Webhook Events from RevenueCat Common webhook events include: INITIAL_PURCHASE RENEWAL CANCELLATION BILLING_ISSUE EXPIRATION SUBSCRIBER_ALIAS πŸ”— For a full list of event payloads, visit: RevenueCat Sample Events ✅ Step-by-Step Guide to Integration 1. Create the Route // routes/ap...

Laravel Relationships Explained – A Beginner-Friendly Guide

Laravel Relationships Explained – Eloquent ORM Guide Laravel's Eloquent ORM provides a beautiful, simple implementation for working with your database. One of its most powerful features is the ability to define relationships between different models. Understanding relationships allows you to link database tables through Eloquent and run complex queries with minimal effort. πŸ“ What is a Relationship? A relationship in Laravel refers to the connection between two or more Eloquent models (database tables). Relationships allow us to access related data using simple methods instead of writing complex SQL joins. πŸ’Ό When Should You Use Relationships? Use relationships when: One model is logically related to another (e.g., a User has a Profile) You want to avoid writing raw SQL JOIN queries You want to access related records easily using model methods 1. hasOne The hasOne relationship defines a one...

Most Common SQL Commands Every Developer Should Know

Most Common SQL Commands Every Developer Should Know SQL (Structured Query Language) is the foundation of working with databases. Whether you're a backend developer, full-stack engineer, or data analyst — knowing how to write SQL queries is a must-have skill. In this post, we’ll go over the most commonly used SQL commands that every developer should know with examples. Let’s get started! 1. SELECT – Retrieve Data This is the most basic and widely used SQL command. SELECT * FROM users; Retrieve all columns from the users table. 2. INSERT INTO – Add Data INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com'); Adds a new record to the users table. 3. UPDATE – Modify Existing Records UPDATE users SET name = 'Jane Doe' WHERE id = 1; Updates the name of the user whose ID is 1. 4. DELETE – Remove Records DELETE FROM users WHERE id = 2; Deletes the user with ID 2 from the t...

How to Write DRY Code in Node.js Using Helper Functions – Beginner’s Guide

How to Write DRY Code in Node.js Using Helpers As developers, one of the most important principles we should follow is DRY: Don't Repeat Yourself . Repetition makes code harder to maintain and debug. In this post, you'll learn how to write cleaner, reusable, and DRY code in Node.js using helper functions. πŸ’‘ What is DRY Code? DRY code means reducing repetition in your codebase. Instead of copying and pasting the same logic multiple times, you extract that logic into a function (or helper), then reuse it wherever needed. πŸ› ️ What are Helpers in Node.js? Helpers are utility functions that handle repetitive tasks like formatting, validation, date conversions, logging, etc. These are usually stored in a separate file (like helpers.js ) to keep the main code clean. πŸ“ Example Project Structure project/ ├── helpers/ │ └── stringHelper.js ├── routes/ │ └── userRoutes.js ├── app.js ✍️ Example: Creating a Helper ...